Semaphores
Question 1 |
Given below is a program which when executed spawns two concurrent processes : semaphore X : = 0 ; /* Process now forks into concurrent processes P1 & P2 */
Consider the following statements about processes P1 and P2:
P1 | P2 |
---|---|
repeat forever V (X) ; Compute ; P(X) ; | repeat forever P(X) ; Compute ; V(X) ; |
- It is possible for process P1 to starve.
- It is possible for process P2 to starve.
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 |
Question 1 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.
P2 can be starves on P, then P1 loops forever.
Both statements (i) and (ii) are True.
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 |
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
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
There are 2 questions to complete.