RE: JavaMemoryModel: Write atomicity for volatiles

From: Doug Lea (dl@cs.oswego.edu)
Date: Sun Jul 22 2001 - 10:59:51 EDT


Sarita wrote:

>
> Serialization of writes to the same location: Do writes to the
> *same* location appear in the same order to all threads? That is, is the
> following execution allowed?
>
> Initially A=B=C=D=0
> Thread 1
> A = 1
> B = 1
>
> Thread 2
> A = 2
> C = 1
>
> Thread 3
> while (B! = 1) {;}
> while (C != 1) {;}
> register1 = A
>
> Thread 4
> while (B != 1) {;}
> while (C != 1) {;}
> register2 = A
>
> Result: register1 = 1, register2 = 2

Proof-by-lack-of-imagination always bothers me, but I have a hard time
imagining any useful multithreaded program that would depend on on the
visibility of writes here to be totally ordered across threads.
Unless anyone can come up with a counterexample, given that it can get
expensive to preserve total orders on big multiprocessors and DSMs, I
don't see any reason to require it.

Offhand though it looks like allowing this could add further
complexity to the underlying model.

-Doug

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



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