WITNESS for pthreads

David Xu davidxu at freebsd.org
Tue Mar 31 18:34:43 PDT 2009

Randall Stewart wrote:
> This was one of the places I was heading (as I wrote privately to Daniel 
> ;-D)
> I suppose I can share it all i.e. the pthread mutex stuff
> will of course work with shared mutexe's but it won't:
> a) Build an easy to use semantic for the app to agree on sharing 
> memory.. i.e. you
>   have left undefined how the process figure out what they are sharing. 
> There is
>   some value in setting up a easy semantic for app dev's to use.
> <i.e. insert the mmap and all the other goo through an additional 
> interface>
> b) What happens when a process exits or hits a core dump while holding one
>   of these mutex's? Is this what you are thinking the PROCESS_SHARED would
>   do??
> <i.e. I don't think a process by itself can fully solve this... maybe the
>    PROCESS_SHARED could be made to help here>

Yes, kernel has to involve in this area, maybe all locking and unlocking
for PROCESS_SHARED mutex should be done in kernel, so kernel can
remember a list of mutex the current thread owned, when the thread exits
for whatever reason, kernel should reset the mutexes to a state and wake
up threads waiting on these mutexes. It seems that Solaris does it in
this way, another way is setting a mutex list pointer in kernel, but
the list itself is in user address space, it is a bit tricky for kernel
to figure out the list's intermediate states when the thread is killed
and fix the mutex states, the benefit is locking and unlocking are fast
because they are done by userland when possible, it seems Linux does it
in this way.

> c) If you build something to do <a> so you have some nice way of naming
>   mutex's you can do something similar to our WITNESS option in the
>   kernel... this is something the few times I have played in user
>   space recently that I have missed... having LOR warnings and such
>   can be a useful tool. You can't have this without <a> IMO.
> I was am interested in a/b but one of my long term intents is to do <c> ;-)
> R

More information about the freebsd-threads mailing list