A counting semaphore S is initialized to 10. Then, 6 P operations and 4 V operations are performed on S. What is the final value of S?
(a) 8
(b) 3
(c) 4
(d) 1
ANSWER:
Question 2
A counting semaphore S is initialized to 7. Then, 20 P operations and 15 V operations are performed on S. What is the final value of S?
(a) 5
(b) 9
(c) 2
(d) 3
ANSWER:
Question 3
A shared variable x, initialized to zero, is operated on by four concurrent processes W, X, Y, Z as follows. Each of the processes W and X reads x from memory, increments by one, stores it to memory and then terminates. Each of the processes Y and Z reads x from memory, decrements by two, stores it to memory, and then terminates. Each process before reading x invokes the P operation (i.e. wait) on a counting semaphore S and invokes the V operation (i.e. signal) on the semaphore S after storing x to memory. Semaphore S is initialized to two. What is the maximum possible value of x after all processes complete execution?
(a) -2
(b) 2
(c) 1
(d) -1
ANSWER:
Question 4
In Question 3, what is the minimum possible value of x after all processes complete execution?