Problema dos Fumantes %% Comentários Não vi problemas nas primeiras soluções, entretanto as duas última podem ter problemas. Alguém mais viu ? *********************************************************** André, Vinícius, Fernando, Marino, João e Jean Semáforo disponivel = 0, acabou_fumar = 0; Agente { while (true) { coloca dois itens na mesa; V(disponivel); P(acabou_fumar); } } Fumante { while (true) { P(disponivel); if (tenho ingrediente complementar) { pega ingredientes da mesa; fuma; V(acabou_fumar); } else { V(disponivel); delay(random()); } } } *********************************************************** Anselmo, Bruno, Caroline, Dairton, Daniela, Gustavo e Leonardo sem mesa = 1, fuma[3] = {0, 0 ,0}; int ingr[3] = {0, 0, 0}; process agente { P(mesa); /* escolhe dois ingredientes aleatoriamente */ ingr[rand % 3] = 1; int r = rand % 3; if (ingr[r] == 1) ingr[(r+1) % 3] = 1; else ingr[r] = 1; V(fuma[0]); } process fumante [i=0..2] { P(fuma[i]); if (ingr[i] == 0) { faz cigarro; fuma; ingr[(i+1) % 3] = ingr[(i+2) % 3] = 0; V(mesa); } else V(fuma[(i+1) % 3]); /* libera o próximo */ } *********************************************************** André, Carlos, Guilherme, Luiz e Rafael sem produzido = 0, agente = 0; int i1, i2; proces agente { while (true) { i1 = produzitem; i2 = produzitem; V(produzido); P(agente); } } process fumante1 { while (true) { P(produzido); if ((i1 == papel && i2 == tabaco) || (i1 == tabaco && i2 == papel)){ i3 = fosforo; fuma(i1, i2, i3); V(agente); } else { V(produzido); delay; } } // os fumantes 2 e 3 são análogos *********************************************************** Daniel, Daniel, Igor, Leandro, Giuliano e Peter sem ingrSem[3] = {0,0,0}, mesalimpa = 0; process fumante[i = 0 to 2] { while (true) { P(ingSem[i]); /* pega os ingredientes */ /* fuma */ V(mesalimpa); } } process agente { while (true) { for(i=0 to 2) { /* põe ingredientes na mesa */ V(ingrSem[fum]); /* acorda o fumante complementar */ P(mesalimpa); } } } *********************************************************** Cristiano, Fabio, Felipe, Fernanda, Luciano, Carolina e João sem fumou = 0; sem fumante[3] = {0, 0, 0}; process Agente { while (true) { poe_2_ingredientes_na_mesa; for( int i = 0 to 2) V(fumante[i]); P(fumou); } } process Fumante[i = 0 to 2] { while (true) { P(fumante[i]); if (ingrediente_complementar) { pega_ingredientes; fuma; V(fumou); } } }