CS439: Principles of Computer Systems
Homework 4, Part 1
Due: 8:45a Friday, February 14, 2014 Part 1 of the
homeworks must be submitted electronically. Please refer to the
homework turnin instructions.
Compare and contrast monitors and semaphores. What is an appropriate
use of each?
Describe the priority inversion problem and give an example
situation where it may occur.
Now consider the following program fragment:
where s1 and s2 are semaphores. All variables are
automatic. Now, consider two threads running this fragment of code
simultaneously. Can there be a deadlock? Why or why not?
You need two Hydrogen atoms and one Oxygen atom to make water.
Using semaphores, write a solution that generates water whenever the
right resources are available. You must have three functions: one to
generate Oxygen, one to generate Hydrogen, and one to generate water.
Assume the three methods may be executed by any number of threads
Solve the water problem using monitors.