- if (threadID >= ActiveThreads || threads[threadID].state == THREAD_INITIALIZING)
- cond_wait(&WaitCond[threadID], &WaitLock);
+ // Retest condition under lock protection
+ if (!( threadID >= ActiveThreads
+ || threads[threadID].state == THREAD_INITIALIZING
+ || (!sp && threads[threadID].state == THREAD_AVAILABLE)))
+ {
+ lock_release(&MPLock);
+ continue;
+ }