More PTHREAD_PROCESS_SHARED(Storing pointers into shared memory?)

[email protected]
Newsgroups gmane.linux.ngpt.devel
Message-ID <[email protected]>
The struct pth_mutex_st is the storage for all of the data required for a mutex.  The pthread_mutex_t type contains a void * that is in reality a pointer to the pth_mutex_st for that mutex.  When NGPT initializes a process shared mutex, it uses a pth_mutex_st structure that is picked from an array that sits in the "ngpt" shared memory area.  A pointer to this structure is stored in the pthread_mutex_t.  This is a direct pointer offset from the address returned from mmap() for the initializing process.  If the program that is sharing this mutex gets a different value (than the initializing process gets) when it calls mmap() for the "ngpt" shared memory area, the pointer that sits in the pthread_mutex_t is invalid and the process crashes or worse.  Bad.

Why store a pointer in the pthread_mutex_t structure, instead of the actual structure?  Any process shared mutexes have to be stored in a shared area anyway, so why the extra "ngpt" shared memory area?

What to do to fix this?  mmap() takes a start parameter to specify the address to map at, but the manpage has this scary story about that:

  The  address  start must be a multiple of the page size. 
  All pages containing a part of the indicated range are 
  unmapped, and subsequent references to these pages will 
  generate SIGSEGV. It is not an error if the indicated 
  range does not contain any mapped pages.

So what value for start would you pick?

I would rather just have everything in the pthread_mutex_t.  That way the storage of shared mutexes is left up to the application, and you don't limit the number of shared mutex per system.  But, it is probably late in the game to make that change...

What is this PTHREAD_MUTEX_ROBUST_NP attribute?

Chris McFarlen
T-NETIX, Inc.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.