What is the wakeup order for sleeping threads?
Raghu Angadi wrote: > A. Hirche wrote: > > > > Is it > > (a) the first thread in the queue (assuming there is an ordered list of > > waiting threads) > > (b) any thread (nondeterministic choice) > > (c) a thread chosen by some other scheme > > Threads are queued in priority order. > > So the thread with the maximum priority will get the mutex. > > If there more than one threads with max priority, then it is > implementation dependant. Not quite! Actually, POSIX places mutex (and condition variable) wakeup ordering requirements only when: 1. The implementation supports the _POSIX_THREAD_PRIORITY_SCHEDULING option. 2. The threads waiting are scheduled using the SCHED_FIFO or SCHED_RR policies defined by POSIX. If these conditions are true, then POSIX requires that threads be awakened in priority order. Multiple threads of identical priority must be awakened “first in first out”. The wakeup order for threads that don’t use SCHED_FIFO or SCHED_RR, (e.g., the default SCHED_OTHER on many UNI