14

Reading Assignment and Discussion Topics
Computer Science 111

for class on Thursday March 23, 2000

Please read Sections 6.4 and 6.5 (we've skipped 6.3) of the Schneider and Gersting text, and be prepared to discuss the following:

1. Suppose that two programs are running at the "same" time, by some scheme discussed in the last class. Both programs need exclusive use of some single system resource, say a printer. The programs get access to the printer by setting some variable in memory, called a flag, to 1 and then resetting it to 0 when they are done. If the flag is already 1 when a program wishes to use the printer, then the program must wait in a tiny loop, checking and re-checking the value of the flag. The loop exits when the flag becomes 0, indicating that the other program has finished with the printer. What difficulties do you see in this arrangement? Remember that the programs might be interrupted at any time.

2. Now suppose that we've solved the above problem, so that single resources can be shared in an orderly way between two programs. What happens if two different resources are both required by both programs? As the text discusses on page 270, this situation can lead to deadlock if each program grabs one resource and refuses to give it up. Deadlock can be avoided if a program gives up any resources it currently has when it cannot get all the resources it needs. Can you think of another way to avoid deadlock, perhaps one in which resources are not given up before being used?