a- Coiffeur
Client
b- Rôle de chacun des sémaphores SCF, SP et SX :
Question 2 : Carrefour
Sémaphores utilisés :
Init (X1, 1), Init (X2, 1), Init (SF1, 1), Init (SF2, 0);
|
Changement
|
Traversee1
|
Traversee2
|
|
{int Feu = 1; |
{ P(SX1); P(SF1); Traversee(); V(SF1); V(SX1); } |
{ P(SX2); P(SF2); Traversee(); V(SF2); V(SX2); } |
SX1 et SX2 sont introduits pour éviter que les voitures attendent sur
SF1 et SF2 et bloquent de ce fait les changements de feu effectués par
Changement.
Question 3 : Opérations atomiques
Réponse :
a- Couples possibles :
x = 0, y = 0
x = 2, y = 0
x = 2, y = 1
b- On utilise un sémaphore S initialisé ainsi : Init(S, 1).
|
Processus
P1
|
Processus
P2
|
| *** P (S); x = x + 1; y = y + 1; V (S); printf("x=%d,y=%d\n", x, y); *** |
*** P (S); x = x * 2; y = y * 2; V (S); printf("x=%d,y=%d\n", x, y); *** |