Philosophe i |
---|
penser(); manger(); |
5 philosophes sont réunis autour d'une table pour manger des spaghetti. Chaque philosophe doit utiliser 2 fourchettes pour manger.
Problème : modéliser le comportement de chaque philosophe pour éviter les privations et les blocages.
Philosophe i |
---|
penser(); P(fourchette i); P(fourchette (i+1) mod 5); manger(); V(fourchette i); V(fourchette (i+1) mod 5); |
Si tous les philosophes prennent en même temps leur fourchette i, il y a interblocage.
|
|
|
test(i) |
---|
si (état[i] == FAIM && état[GAUCHE] != MANGE &&
état[DROITE] != MANGE) alors . état[i] = MANGE; . V(s[i]); |