Next: Children outlive their parents
Up: Assignment 4: Multi-threaded Programs
Previous: Find out where the
In class, we will be discussing a race in which one thread
tries to increment a variable while the other tries to decrease
it. Let's say we start with the variable at n. We declare
victory if the variable ever gets to 0 or 2n.
- 1.
- Modify your program so that it conducts this race. Of
course, if n is small, you would expect whichever process
runs first to win. But if it takes more than one quantum to
iterate n times, then there might actually be some back and
forth. In fact, if the CPU scheduler strictly alternates,
the program may never terminate.
- 2.
- Try out some different values of n and see how long the
program takes. I am not sure whether this will work or not, but
it is possible that we will be able to estimate the quantum
this way (or at least guess what the order of magnitude is).
- 3.
- Try this experiment on iris12, too. How do you expect the
behavior to differ if the two threads are running on different
processors?
Allen B. Downey
3/5/1998