Re: pthread_cond_signal/broadcast: necessary to hold mutex?
Jörg Sonnenberger <[email protected]> Thu, 26 Mar 2026 11:42:57 +0100
| Newsgroups | gmane.os.netbsd.current |
|---|---|
| Message-ID | <[email protected]> |
On 3/25/26 4:40 PM, Robert Elz wrote: > Date: Tue, 24 Mar 2026 20:37:13 -0400 > From: Greg Troxel <[email protected]> > Message-ID: <[email protected]> > > | J�rg Sonnenberger <[email protected]> writes: > > | > Neither signal nor broadcast unlocks the mutex. Only cv_wait may > | > release the mutex before blocking. > | > | Makes sense but I can't find that in the POSIX text. > > That would be: > > The pthread_cond_broadcast() or pthread_cond_signal() functions > may be called by a thread whether or not it currently owns the mutex > > If those functions don't know whether or not the caller owns the mutex, > clearly they can't go manipulating the thing, if the current thread doesn't > own it, some other might have it locked, and not appreciate it suddenly > becoming unlocked, for no apparent reason to it. No, that doesn't justify that they don't unlock the mutex. But at the same time, unlike e.g. pthread_cond_wait, there is nothing given them the liberty to release the mutex either. Joreg