Re: JavaMemoryModel: Code that sleeps and expects to see changes

From: Paul Haahr (haahr@jivetech.com)
Date: Sun Oct 24 1999 - 14:41:00 EDT


> As much as I would be happy to rule that programs that sleep in a loop
> without synchronization and expect to see changes are just wrong, I
> think this may be the one area where the strongest reeducation
> campaign is needed.

Is there anything philosophically wrong with declaring that Thread.sleep
has the same effect on memory as synchronizing and then unsynchronizing
on a monitor? I can't imagine that it would affect the performance of
any real code, and it seems better to bless the status quo assumption
than to embark on a massive reeducation campaign.

Of course, that still doesn't address the issue of how thread 1, from
your previous example:

    if (command.equals("quit") {
        terminateProgram = true;
        return;
    }

ensures that its write of terminateProgram gets flushed to global memory.

--p
-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



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