Re: JavaMemoryModel: Array

From: Jeremy Manson (jmanson@cs.umd.edu)
Date: Tue Dec 11 2001 - 19:05:17 EST


Cliff Click wrote:

>
> Jean-Philippe Lesot wrote:
>
> > I need a way to prevent
> > such optimizations without using method call but using classic array access.
> >
> > Is it possible in the present Java Memory Model? And in your proposition?
>
>
> Insert a lock/unlock between the array refs.
>

I thought we had decided that thread-local and other "useless"
synchronization could be eliminated. No?

My question is, why does he need to prevent those optimizations without
needing to perform further synchronization with a thread reading the
array? Consider the following:

a[1], y are initialized to 0.

Thread 1:

a[1] = 1;
a[1] = 2;
y = 1;

Thread 2:

if (y == 1)
  x = a[1];

On a weak memory order processor (or DSM), x can be any of 0, 1 or 2.
You should have synchronization there.

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