libthr shared locks

Konstantin Belousov kostikbel at gmail.com
Wed Feb 17 16:16:24 UTC 2016


On Tue, Feb 16, 2016 at 04:17:46PM +0000, Martin Simmons wrote:
> >>>>> On Mon, 15 Feb 2016 19:56:21 +0200, Konstantin Belousov said:
> > 
> > One process which executed pthread_barrier_init(), performed what you
> > proposed. What should do the pthread_barrier_wait() call in another
> > process, which shares the 'barrier' with the first process, but does
> > not share the whole address space ? After your pthread_barrier_init()
> > executed, barrier contains the address of the object (off-page) in the
> > other address space, for that process.
> 
> Ah, sorry, I understand now (the init functions are called before any
> sharing).
Well, the memory is either already shared between processes, or it should
become shared before other process may operate on the object carried by
the memory.  It is that pthread_mutex_init() must be called before any
other pthread_mutex_*() functions, but only once globally.

> 
> How should the destroy functions be used by the processes?  I.e. should only
> the "last" process call destroy or can every process call it?
Hm, this is a good observation.  pthread_mutex_destroy() must be called
only by last process, i.e. no other pthread_mutex_* calls are allowed for
the object after the _destroy() was called.

What this means for my implementation, is that processes other than the
_destroy() caller keep the record in the pshared cache, and this needs
fixing. For now, I added a mechanism which scans the whole hash and
re-checks the validity on any object destroy. This can be optimized,
e.g. by doing the scan only each N calls to _destroy(), or by scanning
only the same hash chain, or by not doing this at all.  I think it is
an acceptable compromise for now.

A specific test for the case is at
https://www.kib.kiev.ua/kib/pshared/pthread_shared_destroy.c

Updated patch
https://www.kib.kiev.ua/kib/pshared/pshared.4.patch


More information about the freebsd-threads mailing list