CSCI 4630 homework assignment 3

Due: Tuesday, 2/13/01

A counter is a shared object supporting three operations: add 1 to the counter, subtract 1 from the counter and fetch the value of the counter.

Give a wait-free implementation of a counter that can be shared by two processes. (The two process solution is simpler than a solution for three or more processes.)

Hint: You will need to have more than one variable for the counter. Do not try to store the count in just one variable. Figure out how each process can get in and do its work even if the other process stops for a long time in the middle of an update of the counter. Write code for each of the three operations.

If the counter changes while one of the processes is reading it, the value obtained by the read must be some value that the counter had while the read was being done. It must be a snapshot of the counter.