tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Q about pthread condition variable usage - mixing interlocks



In article <63F5D53A-2767-48F2-B7FA-FBFE93F63874%me.com@localhost>,
Jason Thorpe  <thorpej%me.com@localhost> wrote:
>As far as I can tell, POSIX has no language that covers this situation,
>so Iâ??m tossing it out here for the hive mind...
>
>Is there ANY situation where, for a given pthread condition variable,
>that using a different mutex as the interlock in two different calls to
>pthread_cond_wait() would EVER be legitimate usage?  I cannot come up
>with any scenario in which this would be appropriate, but who knows what
>some crazy applications might do.
>
>POSIX for whatever dumb reason allows pthread_cond_signal() /
>pthread_cond_broadcast() without holding the interlock, but at least
>thereâ??s explicit language about this in the spec (and thankfully the
>language contains a mild finger-wag about it).  But as I said, the spec
>is silent on this particular question, and hopefully itâ??s because the
>answer is â??NO THAT IS A COMPLETELY STUPID THING TO DO AND ANY SELF
>RESPECTING THREAD LIBRARY WILL IMMEDIATELY CAST YOUR APPLICATION INTO
>THE NINTH CIRCLE OF HELL IF YOU TRY ITâ??.
>
>What say you, smart people?
>
>Merci dâ??avance.

We should at least add language in our manual pages explaining that
holding the mutex - while not required - is highly desired, and will
make things work reliably. Currently I don't see anything mentioning
the mutex in our man pages (the opengroup ones do mention it).

christos



Home | Main Index | Thread Index | Old Index