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?
thanks,
Doron.
--- Sylvia Else <sylviae@optushome.com.au> wrote:
> Hi
>
> In the specification, there are several places where
> a total order is
> stated to exist. It is not always clear to me
> whether that is intended to
> be a requirement, or merely a side observation.
>
> In the case of synchronization, the specification
> says
>
> "There is a total order over all lock and unlock
> actions performed by an
> execution of a
> program".
>
> Consider two threads, where each letter represents a
> lock and unlock action
> on a named object's monitor.
>
> Thread 1 Thread 2
> A
> A
> X Y
> B
> B
>
> Does a total order exist here? In particular, what
> is the order of the
> locks on X and Y?
>
> The two threads may be running on separate
> processors, which are separated
> in space. If the lock operations occur sufficiently
> closely in time, then
> there is no defined order for them.
>
> It might seem that an order can be determined by
> looking at the operations
> in main memory, but these are different memory
> locations and could involve
> separate memory hardware, data bus, etc. Indeed,
> these locking operations
> do not necessarily have to go as far as main memory
> anyway. The JVM may be
> scheduling threads in a way such that X is not
> visible to any thread that
> will run on processor 2, and Y is not visible to any
> thread running on
> processor 1. In that case there is no need for the
> main memory to be
> involved in these locks, and to talk about their
> order may be entirely
> meaningless.
>
> A real multiprocessor system that is necessarily
> spread out through space
> can simulate the behaviour of a system that is
> located in one place, and
> thereby provide a total order, but only at the cost
> of limiting its
> performance.
>
> Are the statements about total order in the
> specification really necessary?
>
> Sylvia.
>
> -------------------------------
> JavaMemoryModel mailing list -
http://www.cs.umd.edu/~pugh/java/memoryModel
=====
Doron Rajwan, mailto:doron@rajwan.org
-------------------------------
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