Concurrent Programming 8893
Assignment 2

Due: Thursday, February 26 at 9:00 am.

For both questions use Semaphore.java as the semaphore implementation.

  1. (Based on Andrews 4.16(b) on p. 195.) Assume one producer process and n consumer processes share a buffer with b slots. The producer can deposit messages only into empty slots in the buffer and every message deposited by the producer has to be fetched by all n consumers before the slot can be reused. Furthermore each consumer is to receive the messages in the order they were deposited. However, different consumers can receive message at different times. Implement your solution in Java using semaphores for synchronization. Your solution must be in a file named assign2_q16b.java (and hence the main class should be assign2_q16b). In comments in your code include a statement of the invariant and key assertions to help explain your solution.
  2. (Based on 4.17(b) on p. 195.) Implement a solution in Java for the dining philosophers problem that focuses on the state of the philosophers rather than the forks. In particular, let eating[5] be a Boolean array; eating[i] is true if Philosopher[i] is eating, and is false otherwise. Use the technique of passing the baton to ensure that your solution is deadlock-free and avoids starvation (i.e., if a philosopher wants to eat, eventually he gets to without making any assumptions about the fairness of the Semaphores). In comments in the code include a global invariant and other relevant assertions. Implement your solution in Java in a file named assign2_q17.java.

Please submit your solutions using web submit.


Back to 8893 homepage

Last modified: Mon 2004.02.16 at 22:10 NST by Dennis Peters