CENG328 – OPERATING SYSTEMS
Homework 4
Question 1: Multiple Readers and Multiple Writers Problem [1]
Implement modified Readers-Writers problem using semaphores and mutex in C. This time there
should be N readers and M writers. Writers must wait readers and also other writers to write while
readers can read the shared document or value whenever they want. Please name your file as
“yourID_q1.c”. You can get these M and N values from user or simply define in your code.
Question 2: The Sleeping-Barber Problem [2]
A barbershop consists of a waiting room with n chairs and the barber room containing the barber
chair. If there are no customers to be served, the barber goes to sleep. If a customer enters the
barbershop and all chairs are occupied, then the customer leaves the shop. If the barber is busy but
chairs are available, then the customer sits in one of the free chairs. If the barber is asleep, the
customer wakes up the barber.
Implement a program using C to synchronize the barber and the customers. Please name your file
as “yourID_q2.c”
Please upload your code as compressed file (“yourID_hw4.zip” or “yourID_hw4.tar”).
References:
[1] [Link]
[2] [Link]