Re: JavaMemoryModel: Performing speculative writes ahead of loops that may not terminate

From: Bill Pugh (
Date: Mon May 31 2004 - 12:22:56 EDT

On May 30, 2004, at 8:01 PM, Eliot Moss wrote:

>>>>>> "Sylvia" == Sylvia Else <> writes:
> Sylvia> At 09:36 PM 30/05/2004 +1000, David Holmes wrote:
>>> Master thread fills in a buffer with work items and then starts a
>>> new worker
>>> thread to process the buffer. Worker threads executes:
>>> while (!buf.empty()) process(buf.take());
>>> workerFinished = true;
>>> where workerFinished is a volatile. Not quite as dramatic as firing
>>> the
>>> missiles, but same basic problem.
> Sylvia> All the actions performed by the loop happen-before the
> setting of
> Sylvia> workerFinished to true. Any thread that reads true from
> workerFinished must
> Sylvia> see the effects of all the actions that happen-before it,
> which includes
> Sylvia> the processing of the work in the buffer.
> Sylvia> I don't see the problem.
> I would agree. The interesting case in this context is where the loop
> does
> only thread-private work, perhaps only on local variables all of which
> have
> been allocated to registers .... EM
> -------------------------------

The standard rule has always been: If you can't be caught, it isn't

In other words, the spec only describes what behaviors are allowed, not
the allowable ways in which to execute a program. If moving a write
ahead of
a non-terminating loop causes behavior that can't be explained any
other way,
it is illegal. But if the move doesn't cause behavior that is
prohibited, it is allowed.


JavaMemoryModel mailing list -

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