Skip to content

Instantly share code, notes, and snippets.

@Hydrotoast
Last active December 13, 2015 18:38
Show Gist options
  • Save Hydrotoast/4956492 to your computer and use it in GitHub Desktop.
Save Hydrotoast/4956492 to your computer and use it in GitHub Desktop.
# No progress
def algo1():
while turn != i:
# no-op
# crit section
turn = j
# remainder section
# No progress
def algo2():
flag[i] = true
while flag[j]:
# no-op
# crit section
flag[i] = false
# remainder section
# No mutual exclusion
def algo3():
while flag[j]:
# no-op
flag[i] = true
#crit section
flag[i] = false
# remainder section
# Satisfies all criteria
def peters_algo():
flag[i] = true
turn = j
while flag[j] && turn == j:
# no-op
# crit section
flag[i] = false
# remainder section
def bakers_algo():
choosing[i] = true
number[i] = max(numbers) + 1
choosing[i] = false
for j in range(len(numbers)):
while choosing[j]:
# no-op
while number[j] != 0 && number[j] < number[i]:
# no-op
# crit section
number[i] = 0
# remainder section
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment