Operating System - OpenVMS
1830045 Members
12575 Online
109998 Solutions
New Discussion

Re: why create sharememory failed in the thread

 
tianbinraindrop
Occasional Contributor

why create sharememory failed in the thread

I had wrote a program,and create sharememory suceessful in process(you can name it main thread also),but failed in thread when threads number is large(about 100).why?
2 REPLIES 2
Travis Craig
Frequent Advisor

Re: why create sharememory failed in the thread

Tianbinraindrop,

My first thought was that having more threads would consume more of your virtual address space, at least with their stacks. If you use the default stack size, though, then 100 thread stacks will use a small percentage of your gigabyte. I wonder whether the stack size was changed with the pthread_attr_setstacksize function.

When you mention creating shared memory, do you mean a global section, shared between processes, or something shared between threads within a process.

Or, do you mean that each thread is creating some memory, in which case you might run out of virtual address space if you make more threads.

I think we need to know what error status you see when it fails, and more details about your program and what it does.

--Travis Craig
My head is cold.
tianbinraindrop
Occasional Contributor

Re: why create sharememory failed in the thread

thank you for answer.My program create about 100 threads to do something.
but use only one thread to map sharememory.The purpose of sharememory is to
share information between processes.I use posix api to create and map sharememory.
The code is list here:
#ifdef __vms
bool CShareMemoryClient::map()
{
int m_memory_handle = shm_open (m_memory_name.c_str(), O_RDWR, 0);
if(m_memory_handle == -1)
{
return(false);
}

struct stat m_stat;
fstat(m_memory_handle,&m_stat);
m_memory_size = m_stat.st_size;

m_pMemory = mmap (0, m_memory_size, PROT_READ | PROT_WRITE, MAP_SHARED, m_memory_handle, 0);
if (m_pMemory == MAP_FAILED)
{
return false;
}

close (m_memory_handle);
return(true);
}
#endif
when the thread run,the first call will fail(at shm_open call).When I decreased threads number,It did well.
I had try pthread-xx-setstacksize,but no effect.