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?



    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�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.

Internal implementation details which allow the code to test who owns a
mutex aren't assumed by the standard.  There are many pthread_mutex* functions
in the standard, but none of them is pthread_mutex_owner (or anything similar).

kre



Home | Main Index | Thread Index | Old Index