Skip to content

Instantly share code, notes, and snippets.

@aerodame
Last active January 29, 2025 04:38
Show Gist options
  • Save aerodame/530368bfda45965e1f4b70de8b620f41 to your computer and use it in GitHub Desktop.
Save aerodame/530368bfda45965e1f4b70de8b620f41 to your computer and use it in GitHub Desktop.
// j = 1-i ; i=0, j=1
// Process Pi
Pi() {
flag[i] = true;
turn = j;
// entry section
while (flag[j] && turn == j); // Busy wait
// Critical Section
// exit section
flag[i] = false;
}
// j = 1-i ; i=0, j=1
// Process Pj
Pj() {
flag[j] = true;
turn = i;
while (flag[i] && turn == i); // Busy wait
// Critical Section
flag[j] = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment