CS 102 (Spring 2003)
Lab 3: Threads, Race Conditions, and Atomicity
Author: Ron K. Cytron
| Lab |
Assigned |
Design Due (In class) 10 AM |
Implement (In Lab) Wednesday |
Demo (In Lab) Wednesday |
Lab Due (In lab) Wednesday |
| | 4 | Feb |
| |
5 | Feb |
12 | Feb |
12 | Feb |
Overview
In this lab you will consider a class with two instance variables.
The invariant for that class is as follows:
The sum of the instance variables should equal 1
This class has a method that exchanges the values of the instance variables,
but the exchange is not performed in a thread-safe manner. Your job will
be to introduce exclusion such that the class becomes thread-safe.
[[[ Download PC zip ]]]
Zip includes:
- Classes you do not implement, but modify as part of this lab:
- Classes you do implement:
Before starting:
Helpful resources:
What to do.
- Following the documentation , complete
the classes you must modify.
- Run your program and observe what happens to the results of the sum.
- Insert synchronization appropriately.
- Run your program again and observe correct behavior.
Notes:
- Be prepared to explain what you did in your lab section.
- You only have to write some 30 lines of code for this lab. Make
those lines simple, elegant, and beautiful.
What to turn in (after demo in your lab section)
- Printouts of all Java files you have modified.
Last modified 15:43:08 CDT 28 April 2003
by Ron K. Cytron