EEL 358 - Operating Systems
Fall 2006
Indian Institute of Technology Delhi, New Delhi



Assignment 4

Synchronization using Pthreads

The objective of this assignment is to let you gain some hands on experience in common concurrent program design and implementation.

Scenario

        There is Barber Shop with multiple Barber¡¦s. You can use any numbers of Barbers minimum is 3.The customers coming for service are served in First-Come-First-Serve basis.

Arrival Rate

        Customer Arrival Rate is such that, one barber is always awake serving the customer, i.e.,  all the Barbers cannot go to sleep at a time.

So if Nq + Ns = = 1 => generate more customers.

And if Nq + Ns >1   => You can decide to generate more customers or not.

         where Nq and Ns are the number of customers in the queue and getting served respectively.

Dispatcher

        Dispatcher is the one who guides the incoming customer to the sleeping barber¡¦s.

           

Implementation

Customers:

Can be data-structures containing information about its

1.      Service time

2.      Arrival time

3.      Status

a.      Served

b.      Waiting

c.       Terminated

             Barber

Is thread with thread-id and status

 Status

1.      Sleeping ¡§if no customers¡¨

2.      Serving   ¡§if customers are waiting to be served¡¨

             Customer generator

It is a thread, which decides whether to generate more customers, or not. It also decides the service time customer needs. The customer¡¦s service time is randomly generated.

 Dispatcher:

It is a thread, which dispatches the customer to the sleeping barber. The dispatching is done in round robin fashion to avoid starvation.

If more customers are there it should put in the queue. Start initially with random customers generated and the entire barber¡¦s are sleeping. You can use any type of signaling between the threads for synchronization.

 

Log file Generation

Generate a log file which has the all the information about the system at any particular instant of time like number  of customers in the queue, number of customers getting service, number of sleeping barbers and what are their ids. The Log file is generated by an extra thread which is automatically triggered as the log time interval expires. The thread after writing log file returns the control to the system.

Sample Output

Text Box: Dispatcher: Sleeping Barbers => 1,2,3,¡K¡K
Customer Gen.: Customer 1,2,3 arrived
Dispatcher: Customer 1 is send to Barber 1
Sleeping Barbers => 2,3,¡K¡K
Dispatcher: Customer 2 is send to Barber 2
Sleeping Barbers => 3,¡K¡K
Barber 2 : Finished Serving .. I m going to sleep
Dispatcher: Customer 3 is send to Barber 3
Sleeping Barbers => 4,¡K¡K,1
Custer Gen.: Customer 4,6,7,8 arrived

   

¡@

¡@

¡@

¡@

¡@

¡@

¡@

¡@

¡@

Marks Distribution

Text Box: Thread Creation:                                                      3          Marks
Synchronization + Scheduling of threads:            10        Marks
Demonstration:                                                         7          Marks
(Proper Input/Output & log file generation)                                           
 
Clarity:                                                                       -2        Marks 
(Missing README file, unclear and uncommented code, variable names are not upto mark, improper coding style)
Late Submission:                                                      -4        Marks
(Only one day Late submission is allowed)
 

 

¡@

¡@

¡@

¡@

¡@

¡@

¡@

Submission

Please submit a tar file on-line containing the following:

The tar file can be uploaded in the assignment # 4 using this link. Please make sure that you upload the assignment only once. In case of multiple submission ONLY first submission will be used for grading.

Deadline

The submission deadline for the assignment # 4 is November 7, 2006 [23:59 Hrs].

Questions

If you have any further questions relating to this assignment, you may contact the TA, Mr. Shashwat Agrawal [Mob - 9910762332].