Skip to content

Instantly share code, notes, and snippets.

@aahung
Created December 14, 2015 20:58
Show Gist options
  • Save aahung/2ba492704491b172a78e to your computer and use it in GitHub Desktop.
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.
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