Operating Systems monitors
$10-30 USD
Pagado a la entrega
High up on Everest, Sherpaas have installed two ropes to assist the climbers in crossing a deep glacier
crevasse.
The rope can hold only a maximum of three climbers at any one time, and they all have to travel in the same
direction. Obviously, you can have two groups of climbers going in opposite directions by using one rope
each.
Create a monitor based solution to this problem. Your program should support an arbitrary number of
climbers/threads, that will be randomly assigned to one or the other side of the crevasse, and they will try to
cross after waiting for a random amount of time. E.g.:
$ ./crossing 25
should create 25 threads.
Your design should follow the “critical section outside of the monitor” approach. Each climber should ask
the monitor for permission to cross in one of the two directions (east-to-west or west-to-east). The monitor
should return the rope id to use for the crossing, if one is available in that direction and it has capacity to
spare. An empty rope could be employed to carry people in any direction.
The output of your program should be similar to this:
Climber 1 is waiting to cross.
Climber 2 is waiting to cross.
Climber 1 is assigned rope 1.
Climber 1 is crossing from east to west using rope 1.
Climber 2 is assigned rope 2.
Climber 2 is crossing from west to east using rope 2.
Climber 2 finished crossing.
Climber 1 finished crossing.
Nº del proyecto: #24750719