Howard Chu wrote:The SUSv3 text seems pretty clear. It says "WHEN pthread_mutex_unlock() is called, ... the scheduling policy SHALL decide ..." It doesn't say MAY, and it doesn't say "some undefined time after the call." There is nothing optional or implementation-defined here. The only thing that is not explicitly stated is what happens when there are no waiting threads; in that case obviously the running thread can continue running.
But it doesn't say the unlocking thread must yield to the new mutex
owner, only that the scheduling policy shall determine the which
thread aquires the lock.
It doesn't say that decision must be made immediately, either (eg.
it could be made as a by product of which contender is chosen to run
next).
Clearly the point is that one of the waiting threads is waken and gets the mutex, and it doesn't matter which thread is chosen. I.e., whatever thread the scheduling policy chooses. The fact that SCHED_OTHER can choose arbitrarily is immaterial, it still can only choose one of the waiting threads.
I think the intention of the wording is that for deterministic policies,
it is clear that the waiting threads are actually worken and reevaluated
for scheduling. In the case of SCHED_OTHER, it means basically nothing,
considering the scheduling policy is arbitrary.