CSE 132 (Spring 2010)
Lab 3a: Maze setup
(Double Locks and Array Review)

Commit your repo and demo to TA before leaving. This lab is more like a studio, with the work due today by end of your lab session.


This is the setup of a lab that will take 2 or 3 weeks in its entirety. Some work will be due each week. For this week, you will apply the double lock solution you developed in Studio 4 to eliminate the deadlock present in the code you are given.

You will also generalize the maze construction beyond the 2×2 maze you are given. This will involve some review of arrays. See the appropriate CSE131 material for support (or ask TA or prof).

Basic part

  1. You are really encouraged, but not required, to work in groups on this lab.
    • If the exact same people are involved, you can use the group name that you used for Lab 2a. Feel free to ask for a new group name if your groups have changed or if you want a fresh start.
    • It's really helpful to have eclipse open on one computer and this lab writeup visible on another.
  2. Open eclipse and update your workspace to see the code for this lab. All of the code is in the lab3a and its subpackages. The structure is like that you saw in Studio 4.
  3. Run the Lab class as a Java Application. Here's what you should be seeing:
  4. As with the Dining Philsophers of Studio 4, let this program run until you see deadlock. If things are too slow, then decrease the DELAY in Lab.
    Explain to a TA or the prof what you see, and what it means in terms of deadlock, before you continue.

Next steps

  1. (5 minutes) OK so you've seen this before. Take a look at the DoubleLock implementation that came with this zip, and observe that it operates unsafely.
    Replace the code in DoubleLock with the code you developed in Studio 4 that works, and run the application again. Make sure that you never see deadlock any more. Remember you can increase the pace of the Lab by modifying DELAY in Lab.
  2. (15 minutes) When the Set associated with a Room changes, the color chosen in SetViz is random. Let's make it dependent on a Room's Set, so that two Rooms are in the same Set, then their visualization will appear the same color:
    Open SetViz in eclipse and look at the method computeColor. Fix that method so that it computes a Color based on the hashCode() of the Room's Set.

    Follow the advice given in comments for computeColor so that you pick colors that will work with the rest of this lab.

  3. (40 minutes) The Maze as given to you creates only a 2×2 maze. Let's generalize this to any number of rows and columns:

Demo your work

To receive credit for lab 3a: