next up previous
Next: What to turn in Up: Assignment 6: Synchronization Primitives Previous: Break the lock

Implement semaphores

1.
Print the man page for blockproc. This is a system call processes can use to block themselves (i.e. indicate to the operating system that they would like to yield the CPU) and to wake up other processes.
2.
Use the correct implementation of locks and blockproc to implement sempahores as discussed in class.

3.
Modify your program from the previous section so that it uses semaphores to enforce mutual exclusion rather than using locks. Check that your implementation enforces mutual exclusion. Of course, it is possible that you will see no synchronization errors even if your implementation is incorrect--there is only so much testing can do for you.

4.
Time the two versions of the program and see which is faster. I suspect that for the type of program we are talking about, the simple locks will be faster than the semaphores. Write a few sentences explaining under what circumstances you would expect semaphores to provide superior performance.

5.
Modify your program so it does different stuff, like CPU-bound loops, or I/O, or whatever you think it will take for the semaphore version to out-perform the lock version.


next up previous
Next: What to turn in Up: Assignment 6: Synchronization Primitives Previous: Break the lock
Allen B. Downey
4/7/1998