Re: JavaMemoryModel: Write atomicity for volatiles

From: Joseph Bowbeer (jozart@csi.com)
Date: Sun Jul 22 2001 - 13:18:17 EDT


The code sample looks like the kind of thing a novice armed with the
knowledge of volatile would try to write.

(Or someone armed with device driver experience.. My first experience with
volatile was when writing device drivers in C, where "volatile" flagged the
control registers on the hardware.)

----- Original Message -----
From: "Doug Lea" <dl@cs.oswego.edu>
To: "Sarita Adve" <sadve@cs.uiuc.edu>
Cc: <javamemorymodel@cs.umd.edu>
Sent: Sunday, July 22, 2001 7:59 AM
Subject: RE: JavaMemoryModel: Write atomicity for volatiles

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