Re: JavaMemoryModel: Total orders

From: Jeremy Manson (jmanson@cs.umd.edu)
Date: Wed Dec 10 2003 - 10:59:19 EST


>
> Suppose there is a data-race, when thread1 sets x=1
> and thread2 sets x=2. At this point, thread3 can read
> x=1 and thread 4 can read x=2, which is fine.
>
> My question is: is the value of x defined?
> Specifically:
> 1. Suppose 1-hour later all 4 threads take a common
> mutex. Will x be defined then?
> 2. Suppose 1-hour later thread5 and thread6 reads x
> for the first time. Do they have to see the same
> value?
>
> As I understand the spec, both answers are false,
> which allows two separate CPUs implementation, when
> the main memory in the first contain x=1 and in the
> second it contains x=2. Is this true?

I think that "defined" may be the wrong choice of words here. When you
are talking about reads, you can really only answer what writes are
visible to a given read. When you asked if something is "defined", you
really meant to have asked if there is only one write visible to those
reads.

I just say that because "x" isn't really "defined" to be anything; a given
read of x *always* has a well-defined set of values it can read.

In the cases you mentioned, though, all reads can see either write.

                                        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:55 EDT