A counting semaphore was initialized to 8. Then 12 P (wait) operations and 7 V…

2022

A counting semaphore was initialized to 8. Then 12 P (wait) operations and 7 V (signal) operations were completed on this semaphore. The resulting value of semaphore is –

  1. A.

    4

  2. B.

    3

  3. C.

    5

  4. D.

    1

Attempted by 254 students.

Show answer & explanation

Correct answer: B

To find the final value of a semaphore, you can use the following simple arithmetic formula:

Final Value = Initial Value - (Number of P operations) + (Number of V operations)

1. Identify the given values:

  • Initial Value (S): 8

  • Wait operations (P): 12 (These decrement the semaphore value)

  • Signal operations (V): 7 (These increment the semaphore value)

2. Perform the calculation:

Final Value = 8 - 12 + 7

Final Value = -4 + 7

Final Value = 3

Conclusion: The resulting value of the semaphore is 3.

Explore the full course: Up Lt Grade Assistant Teacher 2025