2.4.1.2.1. Naive Passive Wait For Critical Section
if (AtomicSwap (bCriticalSectionBusy, true))
{
// The critical section is busy, put
// the process into the waiting queue
oWaitingProcesses.Put (GetCurrentProcess ());
// Wait until somebody wakes the process
Sleep ();
}
// Code of critical section comes here
...
// See if any process is waiting in the queue
oWaitingProcess = oWaitingProcesses.Get ();
if (oWaitingProcess)
{
// A process was waiting, let it enter the critical section
Wake (oWaitingProcess);
}
else
{
// No process was waiting, mark the critical section as free
bCriticalSectionBusy = false;
}