next up previous
Next: Submit Your Program(s) Electronically

Programming Project Three
Computer Science 4334 -- Fall 2000
Operating Systems

CSCI4334 Assigned: Friday October 13, 2000
  Due: Friday October 20, 2000

In this assignment, you are to write two separate programs to experiment with process coordination. The first program implements the bounded buffer problem. The textbook has a solution on page 200 (Figure 8.14). You may just copy that solution. The actual semaphore operations in Linux have different names than the one in the figure. You have to change them properly to make it work. Consult the example at Note that you have to compile the program with library option 'pthread' and 'rt', i.e. +gcc -o pcsem p-c-sem.c -lpthread -lrt+.

Your second program is to implement the Sleepy Barber Problem. We discussed it in the class. See the Problem 9 on page 211 of the textbook. In the textbook you are only asked to write the code segment. In this exercise, you are required to write a complete program using semaphores. Here is the outline of the solution as we discussed in the class. You are to write a complete program for it.

customer()                             barber()
{                                      {
   while (TRUE)                           while (TRUE)
   {                                      {
      customer = nextCustomer();             P(waitingCustomer);
      if (emptyChairs == 0)                   P(mutex);
         continue;                             emptyChairs ++;
      P(chair);                                takeCustomer();
       P(mutex);                              V(mutex);
        emptyChairs --;                      V(chair);
        takeChair(customer);               }
       V(mutex);                        }
semaphore mutex = 1, chair = N, waitingCustomer = 0;
int emptyChairs = N;

Your program won't be responsible for real hair cutting. Rather the program will print a message when the action is taking place, for example, ``Customer is taking a chair''.

next up previous
Next: Submit Your Program(s) Electronically
Meng Xiannong 2006-07-14