Re: JavaMemoryModel: Problem with Thread.sleep

From: David F. Bacon (
Date: Mon Oct 25 1999 - 11:30:32 EDT

David Holmes writes:
> I don't quite understand where David is coming from on this. Under the
> current JMM the examples that have been shown are not guaranteed to reflect
> any updates in the variable polled without synchronisation. These variables
> should either be marked as volatile or accessed under sync.

David appears to have been mistaken :-(. I don't know why, but I was sure that
the JMM provided for such unsycnhronized, non-volatile polling. But it
certainly doesn't seem that way based on chapter 17.

Just so we're clear: I don't advocate that style of programming, and I'm very
happy to discover that I was wrong. So I agree with Doug: file lots of bug

Bill Pugh writes:
> The question is what does sleep do? Is it simple a most cost
> effective way of waiting for a certain number of milliseconds than a
> timing loop, or does it has synchronization semantics?

Since sleep() will usually cause a thread switch, it seems reasonable to have
it synchronize. But it shouldn't be necessary to mention that in the JMM; it
should simply be a result of sleep invoking synchronized().

JavaMemoryModel mailing list -

This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:21 EDT