[concurrency-interest] Volatile array and Wait
jmanson at cs.purdue.edu
Tue Oct 18 00:30:04 EDT 2005
> Question 1) I have an array e.g. volatile long a1 = new long;
> 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, a1...) 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
Hope that helps!
More information about the Concurrency-interest