On Mar 17, 2004, at 10:48 PM, Eliot Moss wrote:
> In particular, if Thread 1 writes 1 into a variable that
> is initially 0, and Thread 2 writes 2, and this happens concurrently
> with
> collection, then depending on which copy of the variable Thread 3
> reads,
> and when, it may see the value go from 0 to 1 to 2 and then back to 1.
> We
> do guarantee no "out of thin air" and that if there are no more
> writes, the
> value eventually stabilizes.
>
> My question is: In the memory model being proposed, is this behavior
> legal?
> (I am hoping so, since if it is not, my clever way of making my
> algorithm
> much cheaper than it would be for C (say) may be undermined.)
>
> I suppose I can frame this as a test case if pressed :-).
>
I'd be more confident answering a test case. So let me propose one:
Initially, x = 0
Thread 1:
x = 1
Thread 2:
x = 2
Thread 3:
r1 = x
r2 = x
r3 = x
r4 = x
Behavior in question: r1 = 0, r2 = 1, r3 = 2, r4 = 1
Decision: Yes, this behavior is absolutely legal, even if you throw a
pile a volatile accesses, dependences
and synchronizations into thread 3 to try to keep the reads of x from
being reorders (so long as thread 3 doesn't synchronize with threads 1
and 2). In fact, thread 3 can also still see the value 0 for x, and x
never has to stablize (unless, for example, thread 3 writes to x).
Bill
-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:01:00 EDT