Semaphores
Question 1 |
Write a concurrent program using parbegin-parend and semaphores to represent the precedence constraints of the statements S1 to S6, as shown in figure below.

Theory Explanation. |
Question 2 |
At a particular time of computation the value of a counting semaphore is 7. Then 20 P operations and 15 V operations were completed on this semaphore. The resulting value of the semaphore is:
42 | |
2 | |
7 | |
12 |
Initial value of S is 7.
So after 20P operations and 15V operations the value of semaphore S will be,
S = 7 - 20 + 15 = 2
Question 3 |
Given below is a program which when executed spawns two concurrent processes:
semaphore X := 0 ;
/* Process now forks into concurrent processes P1 & P2 */
P1: repeat forever P2: repeat forever
V(X); P(X);
Compute; Compute;
P(X); V(X);
Consider the following statements about processes P1 and P2:
I. It is possible for process P1 to starve.
II. It is possible for process P2 to starve.
Which of the following holds?
Both 1 and 2 are true | |
1 is true but 2 is false | |
2 is true but 1 is false | |
Both 1 and 2 are false |
P2 can be starves on P, then P1 loops forever.
Both statements (i) and (ii) are True.
Question 4 |
Consider the following program segment for concurrent processing using semaphore operators P and V for synchronization. Draw the precedence graph for the statements S1 to S9.
var
a, b, c, d, e, f, g, h, i, j, k : semaphore;
begin
cobegin
begin S1; V(a); V(b) end;
begin P(a); S2; V(c); V(d) end;
begin P(c); S4; V(c) end;
begin P(d); S5; V(f) end;
begin P(e); P(f); S7; V(k) end;
begin P(b); S3;V(g);V(h) end;
begin P(g); S6; V(i) end;
begin P(h); P(i); S8; V(j) end;
begin P(j); P(j); P(k); S9 end;
coend
end; Theory Explanation. |
