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

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

Get the starting program like this...

  Log on to Odin server.

  $ umask 027
  $ cd 3600/9
  $ cp /home/fac/gordon/public_html/3600/examples/9/crash2.c mylab9.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.



Optional...

Create new file 3600/9/mylab9a.c

If a West-bound car enters the intersection, an East-bound car could also enter
the intersection, and no collision will occur.

Then, when both the East-bound and West-bound cars are out of the intersection,
the North-bound and South-bound cars could use the intersection for a while.

This is very similar to the "Readers have priority" thread functionality we saw
in the examples in lecture. This thread strategy can actually be used to make
the cars use the intersection more efficiently.

The cars in the intersection are the readers. When the number of readers goes
to zero, a new set of readers can use the intersection.

This solution can be done using two semaphores. The code will be very similar
to the reader code we saw in the two samples from lecture.



Files to be collected...
  mylab9.c
  Makefile