Skip to content

Instantly share code, notes, and snippets.

@tonussi
Last active December 19, 2015 10:59
Show Gist options
  • Save tonussi/5944285 to your computer and use it in GitHub Desktop.
Save tonussi/5944285 to your computer and use it in GitHub Desktop.
Problema do Barbeiro Dorminhoco em Python, Tradução C-like -> Python de Andrew S. Tanenbaum Distributed Operating System, Prentice-Hall, 1995. Página 82.
Semaphore barbeiro = 0
Semaphore acentos = 1
Semaphore pronto = 0
int nro_acentos_livres = N
def Barbeiro():
while true:
wait(pronto)
wait(acentos)
nro_acentos_livres += 1
signal(barbeiro)
signal(acentos)
def Consumidor():
while true:
wait(acentos)
if nro_acentos_livres > 0:
nro_acentos_livres -= 1
signal(pronto)
signal(acentos)
wait(barbeiro)
else:
signal(acentos)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment