Re: JavaMemoryModel: Word tearing

From: Bill Pugh (pugh@cs.umd.edu)
Date: Thu Jan 03 2002 - 15:37:31 EST


At 3:22 PM -0500 1/3/02, Doug Lea wrote:
>
> Normally (according to proposed JSR-133 semantics) if you share an
> array across threads, you need to make it volatile (or synchronize
> use).
>
> But if you happen to know that no two threads will ever read/write
> to the same array cell, should you still declare it volatile?
>
>My answer is yes.
>
>The answer is motivated by underlying word-tearing issues, but
>I think "yes" is a good answer in any case.

My answer is no.

First, JSR-133 will allow word tearing only if I am forced to resign
from the expert group. Java will not have word tearing, and we just
need to make sure the VM implementers know the implications of that.

Second, you can't declare an array as volatile. You can only declare
a field that stores a reference to an array as volatile, and that
field will typically only be written once. So declaring the field as
volatile doesn't do anything useful to force visibility between the
threads.

        Bill
-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:37 EDT