Develop a solution to implement below rules using semaphores.

A bridge on a busy highway is damaged by a flood. One-way traffic is to be instituted on the bridge by permitting vehicles traveling in opposite directions to use the bridge alternately. The following rules are formulated for the use of the bridge:

  1. (1) At any time, the bridge is used by vehicle(s) traveling in one direction only.
  2. (2) If vehicles are waiting to cross the bridge at both ends, only one vehicle from one end is allowed to cross the bridge before a vehicle from the other end starts crossing the bridge.
  3. (3) If no vehicles are waiting at one end, then any number of vehicles from the other end is permitted to cross the bridge.

Develop a solution to implement these rules using semaphores.

Solved
Device Management 1 Answer Anonymous(s) Post