Operating Systems Tutorial 3 University of Wales, Cardiff
This tutorial is not assessed, but it is in your interest to
attempt it, because SOON there will be one that is.
Cars coming from north and south must pass over a bridge across a river.
Unfortunately there is only one lane on the bridge. At any time there can
be one or more cars travelling in the same direction on the
bridge. Write an outline of procedures (as pseudo-code) which must
be called by a process representing a car as it enters and leaves the
bridge.
You will require four procedures :
Narrive - North bound car arriving
Ndepart - leaving bridge
Sarrive - South bound car arriving
Sdepart - leaving bridge
Southerly car : Sarrive(); cross Sdepart() Northerly car : Narrive(); cross; Ndepart
Give an implementation of the procedures using semaphores to provide
synchronisation
Hint : use counts for north and south bound cars and semaphores
to give mutual exclusion to the counts. Another semaphore is needed
to indicate the bridge is free
Discuss the fairness of your solution.
Omer Rana
March 1997.
Omer F Rana