Current-Users archive

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

Re: pthread_cond_signal/broadcast: necessary to hold mutex?





On 3/25/26 4:40 PM, Robert Elz wrote:
     Date:        Tue, 24 Mar 2026 20:37:13 -0400
     From:        Greg Troxel <gdt%lexort.com@localhost>
     Message-ID:  <rmi4im4agna.fsf%s1.lexort.com@localhost>

   | J�rg Sonnenberger <joerg%bec.de@localhost> 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


Home | Main Index | Thread Index | Old Index