At 06:01 PM 14/04/2004 -0400, Bill Pugh wrote:
>Say that external() is a function that interacts
>with the world outside of a JVM (e.g., it writes
>to a socket). For simplicity's sake, assume it both
>influences and is influenced by the outside world.
>
>Would a compiler ever want to reorder
>
> * a read of a variable and a following
> call to external() ?
>
> * a call to external() and a following
> write to a variable?
>
> In these cases, I talking about a normal,
>non-volatile variable.
>
>Bill
Yes to both, I think.
a = b;
call to external();
do something with b;
May want to defer setting a = b until after the call, to take advantage of
the read of b required then in 'do something with b'.
for some other purpose calculate value that will be written to a.
call external();
write calculated value to a;
may want to prescient write a before the call to external(). Of course in
this case, the call to external must not be capable of throwing an
exception, but that may be the case.
In both scenarios, this is only possible if external() cannot result in
accesses to the variable a from the current thread, but the compiler may be
able to deduce this.
Sylvia.
-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:01:04 EDT