[concurrency-interest] Volatile array and Wait

Jeremy Manson jmanson at cs.purdue.edu
Tue Oct 18 00:30:04 EDT 2005

Vijay wrote:
> Question 1) I have an array e.g. volatile long[] a1 = new long[100];
> Now, is the object a1 volatile or every element of array a1 is
> volatile or both?

The reference is volatile; the elements of the array are not.  Writes to
a1 will be volatile; writes to elements of a1 (a1[0], a1[1]...) will not.

> Question 2) When we come out of wait state, is it the same thing as
> entering a synchronized block? Will all the variables be taken from
> RAM again instead of from the register buffer?

When you wake from wait(), you must reacquire the lock before 
proceeding; it therefore has the same semantics as a lock acquisition.

It is a little dangerous to think of these semantics in terms of main 
memory and buffers, for reasons that have been discussed in detail on 
this list.

Hope that helps!


More information about the Concurrency-interest mailing list