GATE Computer Science · Operating Systems and Computer Networks · hard

Consider a counting semaphore S initialized to 7. If 12 wait(S) (P) operations and 8 signal(S) (V) operations are completed on S without blocking deadlock, and separately another binary mutex M is used by 5 threads, which two statements are true? (Select two.)

Published · Last updated · checked before publication — how we verify questions

Options

  • AThe final value of the counting semaphore S after the operations is 3Correct answer
  • BThe final value of the counting semaphore S after the operations is 11
  • CFive competing threads can execute inside the mutex critical section simultaneously
  • DAt most 1 thread can be inside the mutex-protected critical section at onceCorrect answer

Answers: A. The final value of the counting semaphore S after the operations is 3; D. At most 1 thread can be inside the mutex-protected critical section at once

A counting semaphore holds a value that wait(S), also called P, decrements by one and signal(S), also called V, increments by one. Starting at 7, twelve completed waits subtract 12 and eight signals add 8, so the final value is 7 - 12 + 8 = 3. A negative intermediate value would only matter if the semaphore used the blocking-count convention. The question states the operations all complete without deadlock, so the net arithmetic gives 3. A binary mutex is a semaphore restricted to the values 0 and 1, and it exists to enforce mutual exclusion. Whatever the number of competing threads, at most one can be inside the critical section at any instant, and the others block until it is released. The most common trap is reversing the signs of wait and signal, which gives 11, or confusing a counting semaphore, which allows several holders, with a mutex, which allows exactly one.

Why the other options are wrong

  • B. The final value of the counting semaphore S after the operations is 11 — This value comes from adding the waits and subtracting the signals, 7 + 12 - 8 = 11, which reverses the roles of the two operations. Wait decrements and signal increments, so the correct result is 3.
  • C. Five competing threads can execute inside the mutex critical section simultaneously — This describes a counting semaphore with a count of five or no protection at all, not a binary mutex. A mutex enforces mutual exclusion, so only one thread can be in the critical section at a time while the other four are blocked.

All Operating Systems and Computer Networks questions and the topic overview →

GATE is a mark of the Indian Institute of Science and the Indian Institutes of Technology. PrepIQ Hub is not affiliated with, endorsed by, or sponsored by the GATE Committee.