This is a modification of Exercise 8 at the end of Chapter 3 of the text.
Uncomment the yield() calls in Class 3.19 make a call to ensureTimeSlicing() in the main method (instituting timeslicing of 100 milliseconds on Solaris) and test it with Program 3.9. No race conditions occur (or rarely); the producer and consumer threads do not (or rarely) deadlock. Why?
Now replace the nap(napping) statements in the producer and consumer run methods of Program 3.9 with
long total = 0; for (int i = 0; i < 100*napping; i++) total += i;(on a slow machine --- use 500 instead of 100 on a fast machine) and retest Class 3.19 retaining the ensureTimeSlicing(). Deadlock now occurs in at least some (if not most) of the runs. Why?
Permission is granted to copy and distribute this material for educational purposes only, provided that the following credit line is included: "Concurrent Programming using Java, Copyright 1997 Stephen J. Hartley." Permission is granted to alter and distribute this material provided that the following credit line is included: "Adapted from Concurrent Programming using Java, Copyright 1997 Stephen J. Hartley.