Homework #2
| Assigned: | October 14th |
| Due: | Tuesday, October 21st at 11:59 PM |
Please read this information on how to submit homework online. Hard copy of homework will not be accepted.
All work on this homework must be your own. Please read (and follow!) the academic honesty policy for this class.
- Would it be possible to write an operating system entirely in C (or another high-level language)? Why or why not?
- Problem 2.19 in the textbook (page 154).
- Problem 2.39 in the textbook (page 156).
- Problem 2.46 in the textbook (page 157).
- In class, we discussed the readers/writers synchronization problem. We noted that a writer might "starve" if a continuous stream of readers kept arriving, never releasing the system to the writer. Modify the code for the readers/writers problem so that writers cannot starve. In particular, a writer should go before all readers that arrive after the writer arrives. The system must otherwise work the same way it does currently. You may assume that semaphores keep waiting processes in a FIFO (simple FCFS queue).
- On a distant planet, there are three genders. They must share a single bathroom with infinite capacity; unfortunately, only members of a single gender may be in the bathroom at any given time. Thus, the bathroom is in one of the following states:
- Empty
- In use by gender 1
- In use by gender 3
- In use by gender 2
- Implement counting semaphores using only binary semaphores and normal (non-atomic) C statements.
enterBathroom (myGender); doMyBusiness (); leaveBathroom (myGender);Write the code for enterBathroom (int gender) and leaveBathroom (int gender) so that an alien sleeps when waiting for the bathroom. You may use any semaphores or counters you might need to solve the problem. Does your solution generalize to n genders?
Last updated 12 Nov 2003 by Ethan L. Miller (elm@ucsc.edu)