CMPS-3600 Operating Systems
Lab-9
Use of mutex for mutual exclusion

Start
Do your work in your Odin 3600b/9 folder.

Get the starting program like this...

  $ cd 3600/9
  $ cp /home/fac/gordon/public_html/3600b/examples/9/crash2.c rvlab9.c

We will build a Makefile together.

Running the program will look like this:



  • The yellow rectangle is the intersection of two roads.
  • The colored boxes are cars driving on the road.
  • The red and green cars are having a collision.
  • Don't let collisions occur.

This program contains several new features.

   1. Double buffering of graphics.
      This eliminates shearing or flickering of graphics animation.

   2. Close window with click on X in title bar.



Assignment...

1. Figure out where the critical section of code is.

2. Protect the critical section with a mutex.

   You may use the same mutex we used in the dining philosophers program.

3. Add some text in the window showing the number of times each
   car passes through the intersection.
   This allows us to check for starvation.


Other things you may add...

4. Add one new car.
   There is room in each lane for another car.
   Choose North, South, East, or West bound.

5. Add one new car to each lane.



Additional...
Apply the "Readers have priority" thread strategy.

Copy your rvlab9.c to rvlab9a.c

Do your work on this in rvlab9a.c

Here's how it might work...

When a car going West enters the intersection, no other cars are allowed in.
But, the car traveling East could also go through the intersection without
any chance of collision with the West-bound car.

Think of cars in the intersection as readers. There can be multiple readers.
East/West cars are one set of readers, and North/South cars are another set
of readers.

The cars waiting at the intersection can be thought of as the writers.
So, as soon as there are no "readers" in the intersection, the waiting
cars become the new readers.



Files to be collected...
  rvlab9.c
  rvlab9a.c
  Makefile