Reading
Threads: S+G Chapter 4 section 5
Synchronization: S+G Chapter 6 sections 1-5, 7. If you like, ignore the
following subsections: 6.2.1, 6.2.2, 6.5.1.
To be turned in
1. S+G exercises 4.6, 4.7
2. S+G exercise 6.1
3. S+G exercise 6.6. By wait and signal, the question is referring to the semaphore operations P() and V() discussed in class. To answer the question, you should show an interleaving of statements that leads to a violation of mutual exclusion.
4. S+G exercise 6.7. Use semaphores to implement your synchronization. A solution without any synchronization in it would look like this:
int customers = 0; void Barber() { while(1) { /* do an infinite loop */ while(customers == 0); /* sleep until a customer arrives */ customers--; /* decrease ctr of waiting customers */ cut_hair(); } } void Customer() { if(customers >= n) return; /* if all chairs are full, just leave */ customers++; /* increase counter of waiting customers */ get_hair_cut(); }