Correct.Robert Hancock wrote:
But the thread the released the
mutex is not one of the waiting threads, and is not eligible for
consideration.
Where are you getting this from? Nothing requires the scheduler to schedule
any threads when the mutex is released.
All that must happen is that the mutex must be unlocked. The scheduler isCorrect. The releasing thread may keep running.
permitted to allow any thread it wants to run at that point, or no thread.
Nothing says the thread that released the mutex can't continue running and
nothing says that it can't call pthread_mutex_lock and re-acquire the mutexWrong.
before any other thread gets around to getting it.
In general, it is very bad karma for the scheduler to stop a thread beforeGood point, except it is a strange program that do this. Lock the mutex once,
its timeslice is up if it doesn't have to. Consider one CPU and two threads,
each needing to do 100 quick lock/unlock cycles. Why force 200 context
switches?