Three processes share a single counting semaphore S whose initial value is 1. All three execute wait(S) one after another, in the order P2, P1, P3. After this, P2 exits its critical section by executing signal(S), and then P1 exits by executing signal(S). What is the value of S after these five operations?
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: A. 0
Explanation
Tracing S step by step from its initial value 1: wait(S) by P2 gives S=0 and P2 enters its critical section; wait(S) by P1 gives S=-1 and P1 blocks in the semaphore's queue; wait(S) by P3 gives S=-2 and P3 also blocks. P2 then calls signal(S), giving S=-1 and waking P1 (which now enters its critical section); P1 then calls signal(S), giving S=0 and waking P3. So after these three wait() and two signal() calls, S = 1 − 3 + 2 = 0, option (i). Note that P3 is still inside its critical section at this point — it has not yet executed its own signal(S).More Computer System Architecture questions
- In the UNIX operating system, when a process creates a child process using the fork() system call, which of the following is genuinely shar…
- A system has 12 instances of a resource R shared among four processes. The maximum need and current allocation of each process are: Process…
- Match List I with List II
- The write operation in I/O operation does the following-
- Which of the following gates do not give output 1 when both the inputs are 0 - A. NAND gate B. NOR gate C. X-OR gate D. X-NOR gate
- Which of the following statements are true ? A. In the write-through policy, only the cache is updated B. In the write-back policy, both ca…