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.

A
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:

A
42
B
2
C
7
D
12
Question 2 Explanation: 
Let the semaphore be S.
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?

A
Both 1 and 2 are true
B
1 is true but 2 is false
C
2 is true but 1 is false
D
Both 1 and 2 are false
Question 3 Explanation: 
P1 can be starves on P, then P2 loops forever.
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; 
A
Theory Explanation.
There are 4 questions to complete.

Access quiz wise question and answers by becoming as a solutions adda PRO SUBSCRIBER with Ad-Free content

Register Now

If you have registered and made your payment please contact solutionsadda.in@gmail.com to get access