PPT Slide
To work, the processes have to agree that:
- A process will not wait forever in EnterCriticalSection().
- Only one process at a time can be in the critical section.
- A process will spend a finite time in the critical section.
- A process that wants to enter its critical section cannot be made to wait for the other process to enter its critical section.
enum { False = 0; True = 1; };
int interested[2] = {False, False};
int turn = 0;
void EnterCriticalSection(int this_process) {
int other_process = 1 - this_process;
interested[this_process] = True;
turn = this_process;
while (turn == this_process && interested[other_process]) {
// do nothing (busy loop)
}
}