Last active
December 19, 2015 10:59
-
-
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.
This file contains hidden or 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
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