More Race Conditions

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?