A mutex for inter-process ;-)

Randall Stewart rrs at lakerest.net
Wed Apr 8 11:08:22 PDT 2009


Ok due to working on a sun benchmark (libMicro) I have
came back to this again :-)

Turns our our friends at sun in their benchmark arrange for
threads in separate process, all started by the same parent
process, to collaborate by using pthread_mutex and pthread_cond
variables. These are allocated in the main process and mmap()'d into
shared memory.  Of course none of this works at all in FreeBSD.

The reason being that both the pthread_mutex_init and pthread_cond_init
under the covers allocate memory for the real pthread_mutex or  
structure.. not the pointer the user hangs on to. So sun's benchmarks
all hang if multiple process are involved since they all go to wait
on a local condition variable ;-)

I suppose in Sun's Solaris the pthread_mutex structure is the entire
structure so that when they mmap it they get it all in shm...

So, what really needs to be done here is we rework the
pthread_cond/mutex to allowed the shared attribute that they are
setting (yes they do this) to actually do something. Of course just
being aware of the issue does not solve the problem.. since you really
need to NOT malloc inside the cond/mutex init code to make this work..  
instead make the "private" structures setup so the user can malloc  

I did  notice that the underlying thr_ library allows one to pass in a
allocator .. this might be useful except for it does not fit in the  

I am not sure how to proceed with this, since it would take some
re-work in the thread library... I could do it but I am sure I would not
do it the way y'all would like :-)

So for now I am going to see about expanding my little toy library that
uses umtx to include cond variables and then adapt the sun libMicro to
use that so I can move forward with all of their benchmarks that do  
stuff :-)

Randall Stewart
803-317-4952 (cell)

More information about the freebsd-threads mailing list