In context of semaphores choose the option with valid codes for wait() and…

2022

In context of semaphores choose the option with valid codes for wait() and signal() functions:

  1. A.

    Wait (s) { while (s) <= 0; s + + } and signal (s) { s - -; }

  2. B.

    Wait (s) { while (s) <= 0; s - - } and signal (s) { s + +; }

  3. C.

    Wait (s) { s - -; } and signal (s) { while (s) <= 0; s + + }

  4. D.

    Wait (s) { s + +; } and signal (s) { while (s) <= 0; s - -; }

Attempted by 79 students.

Show answer & explanation

Correct answer: B

A Semaphore is a synchronization tool used in operating systems to control access to shared resources.

The standard semaphore operations are:
Meaning:
wait() / P() operation
Checks whether a resource is available.
If not available, the process waits.
When available, it decreases the semaphore value.
signal() / V() operation
Releases the resource.
Increases the semaphore value.

Explore the full course: Hpsc Pgt Computer Science