CS3331 Reading List: Week 10

Course Material
Slides used in class are available in the common directory with filename 08-Semaphores.pdf and 09-Race-Conditions.pdf.
Study Multithreaded Programming with ThreadMentor: A Tutorial
  • If you wish to install ThreadMentor on your home machine, the common directory has three files: ThreadMentor-Fedora.tar.gz for Linux 32-bit, ThreadMentor-Linux64.tar.gz for Linux 64-bit, and ThreadMentor-Win32-VSNet2005.zip. Sorry, there is no Mac version.
  • A ThreadMentor FAQ page for Linux and Windows is available here.
If you wish to print these slides, print them double-sided and print as many slides as possible on the same page. Let us save a tree!

Programming Material
Do Programming Assignment IV.

Homework Assignment
Do the following problems:
  • A restaurant has n tables, each of which can only sit one customer, and has the following rules.
    • The restaurant is empty initially (i.e., no waiting and eating customers).
    • When a customer arrives, if there is a free table, he could sit down and order food.
    • When a customer arrives, if all tables are occupied, he must wait until all n customers finish eating and leave.
    • After finishing his food, a customer leaves.
    Design a customer thread with semaphores to simulate this activity.
  • As you know MTU does not have many female students. To restrict the number of male party goers, a fraternity party made an odd rule to maintain the number of male and female students in its party. This rule states that a female student must be accompanied by two male students to enter the party room. Write a thread to simulate male students and another thread to simulate female students using semaphores so that this 2-1 relation is maintained. Can you extend your solution to 3-1 and even n-1?
  • The above rule has a loop hole, because a student could sneak out of the party room and get more students in. As a result, the 2-1 ratio cannot be maintained. To close this gap, let us make the rule a bit more strict. A 2-1 triple must form to enter and exit the party. In other word, once two male students and one female student form a triple to enter the party room, they must also form a 2-1 triple in order to leave the party before reentering the party again. Of course, the exit 2-1 triple may not be the same as the enter 2-1 triple. For example, John, Jason and Mary form an enter 2-1 triple; but, John, Mike and Jane could form an exit triple. In this way, the 2-1 rule is maintained. Will your solution be different from the previous one? (Hint: the bounded-buffer problem may help, again.)
We do not collect your practice work; but, similar problems will appear in quizzes and exams in the future. Note that I will not make any announcement in class for these short quizzes. In other word, short quizzes may take place at any time as long as I see it is appropriate.