What is value of binary semaphore "S" after executing 10 P (Wait) operations if the initial value of "S" is 1? how many process will be blocked?
Познач ознаки найвищого (п’ятого) рівня спілкування
Укажи, на яких фото люди дбають про своє здоров’я
Познач способи зараження ВІЛ / СНІД
boolean blocked[2];
int turn;
void P(int id) {
while(true) {
blocked[id] = true;
while(turn != id) {
while(blocked[1-id])
/* do nothing */;
turn = id;
}
/* critical section */
blocked[id] = false;
/* remainder */
}
}
void main() {
blocked[0] = false;
blocked[1] = false;
turn = 0;
parbegin(P(0), P(1)); //RUN P0 and P1 parallel
The above code provide satisfies progress or not?Binary semaphore S1=1 and S2=0
int x=10
| p0(){ p(s1) x=x+1 v(s2)} | --------------- | p1(){ p(s2) x=x+1 v(s1)} |
|---|
what will be the value of x after execution of p0 and p1?