Created
December 14, 2015 20:58
-
-
Save aahung/2ba492704491b172a78e to your computer and use it in GitHub Desktop.
Describe how the Swap() instruction can be used to provide mutual exclusion that satisfies the bounded-waiting requirement.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
do { | |
waiting[i] = true; | |
key = true; | |
while (waiting[i] && key) Swap(&key, &lock); | |
// critical tasks | |
j = (i + 1) % n; | |
while (i != j && !waiting[j]) j = (i + 1) % n; | |
if (i == j) lock = false; | |
else waiting[j] = false; | |
} while (true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment