next up previous
Next: Estimate the quantum size Up: Assignment 6: Synchronization Primitives Previous: Reading

Break the lock

1.
Pick up the code from

http://rocky.colby.edu/cs357/code/hw6/
The file lock.c contains an incorrect implementation of a lock written in C. The file lock.s contains a correct (I think) implementation of a lock written in Intel x86 assembler code. I will explain the latter in class. The Makefile shows how to make two programs called goodlock and badlock based on the two versions of a lock. Compile and run both programs.

2.
Write a program that uses at least two threads and that accesses a shared variable concurrently. Use your lock to enforce exclusive access to the shared variable. Now test whether your program is in fact achieving mutual exclusion.

There are many ways to do this. Here is just one suggestion: make the shared variable a counter that hands out unique identifiers in sequence. Create a big array and count the number of times each identifier gets handed out. If the lock is working correctly, every identifier should get handed out exactly once, so each array element should be 1.

3.
What is the frequency of synchronization errors using the defective lock implementation?

4.
What is the frequency of synchronization errors using the ``correct'' lock implementation? How can we prove that the implementation is correct?


next up previous
Next: Estimate the quantum size Up: Assignment 6: Synchronization Primitives Previous: Reading
Allen Downey
2000-04-01