In the uncontended case a mutex can be acquired entirely in user-space.
When a contended mutex needs to be acquired, some implementations (Solaris and HP-UX, but not Linux) try to spin for some time in user-space on SMP systems to try to avoid using potentially costly kernel synchronisation primitives. Particularly HP-UX tries very hard and even repeatedly calls sched_yield before finally resorting to ksleep.
A straightforward implementation of pthread_cond_broadcast (one that wakes up all waiters at once) can be quite inefficient as all waiters will usually have to contend for the mutex associated with the condition variable (HP-UX is known to be implemented that way).
If the notifying thread owns the mutex (which is not mandated by the POSIX specification) can queue the waiting threads to be woken up one by one when the mutex is unlocked (and thus avoiding contention).
Revision: 1.1, cmeerw.org/notes/posix_sync.html|
Last modified: Sun Aug 12 11:31:36 2007
Christof Meerwald <email@example.com>