Re: JavaMemoryModel: Prescient reads unnecessary?

From: Jeremy Manson (jmanson@cs.umd.edu)
Date: Wed Nov 12 2003 - 13:04:32 EST


> I could attempt to prove these properties myself, but I figured it's
> easier to ask those whose insight in the JMM is such that they can tell
> immediately. :-)

I like that idea. If only wishing made it so.

Your intuition is reasonable, in the sense that we are always performing
at least one write presciently. However, it often turns out that you need
prescient reads to help with prescient writes. Take the following
example:

Thread 1
 a = 1;

Thread 2
 r1 = c;
 r2 = a;
 b = r2;

Thread 3
 r3 = b;
 c = r3;

A compiler may want to move "r1 = c" to the end of Thread 2. This allows
for the write in Thread 1 to be seen in Thread 2, communicated to Thread
3, and then read by "r1 = c" in Thread 2. Result: r1 = r2 = r3 = 1.

The justification order for this (where all values read or written are 1)
is:

a = 1;
r2 = a; // prescient read
b = r2; // prescient write
r3 = b;
c = r3;
r1 = c;

We need the prescient read because we can only perform the write to b of 1
early if we know that that read will return 1. So, in this case, we need
to perform a prescient write and a prescient read to "help" with it.

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



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