Operating Systems
HW # 4
Synchronization Using Semaphores
- Problem 1 The One-Lane Bridge (25 points)
Cars coming from the east and the west arrive at a one-lane bridge. Cars heading in the same direction can cross the bridge at the same time, but cars heading in opposite directions cannot. Develop a solution to this problem using semaphores for synchronization. Make sure its fair.
- Problem 2 The Hungry Birds (25 points)
Given are four baby birds and one parent bird. The baby birds eat out of a common dish that initially contains five portions of food. Each baby repeatedly eats one portion of the food at a time, sleeps for a while, and then comes back to eat. When the dish becomes empty, the baby bird that empties the dish awakens the parent bird. The parent refills the dish with five portions, and then waits for the dish to become empty again. This pattern repeats forever.
Represent the birds as processes and develop code that simulates their actions. Use semaphores for synchronization.
NOTE:
- Writing your code using the Pascal-like notation in the textbook is recommended, but not required
Please make sure your programs are clear.
- Homework must be submitted by email to TA