Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 01 Apr 2011 00:24:35 -0500 Date: Thu, 31 Mar 2011 22:24:33 -0700 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: AtomicReferenceArray writes and visibility References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <5rSdnZ3R1d8O_AjQnZ2dnUVZ_qWdnZ2d@earthlink.com> Lines: 34 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 75.8.126.96 X-Trace: sv3-m9BtYWZNNp4/IDVrBhMrsfNBgqfTJ9CX4nS5a3zymlBah+7X1AlWsjb0nIGmQpZ2I1B9I52cahpuBJI!HEa4Dzdbmn2HCu90z7fIqcekdv9wfX1Vq1Cvh216W9TtVJ27a3b/utMGY2G8ADJosrlCe9XyqSTz!5UNGDYqdpNfKLYJ0KbBEL78Xvfpbbxb+QM1IHL7jAWE= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2713 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:2691 On 3/31/2011 9:58 PM, markspace wrote: > On 3/31/2011 9:54 PM, Peter Duniho wrote: >> On 3/31/11 9:22 PM, markspace wrote: >>> [...] >>> Read the source code for the AtomicReferenceArray. set() doesn't use any >>> synchronization. It calls sun.misc.Unsafe#putObjectVolatile(). I don't >>> see how that's going to create a happens-before. >> >> "volatile" creates the happens-before. All writes before a volatile >> write in the same thread must be visible in a given thread after a >> volatile read in the same thread from the same location. > > > I didn't notice the keyword volatile there. Did I miss it? The relevant use of "volatile" is in the java.util.concurrent.atomic package documentation, http://download.oracle.com/javase/6/docs/api/java/util/concurrent/atomic/package-summary.html "The memory effects for accesses and updates of atomics generally follow the rules for volatiles, as stated in The Java Language Specification, Third Edition (17.4 Memory Model):" It goes on to map atomic operations to volatile operations. For example "get has the memory effects of reading a volatile variable." > Regardless, the lack of any guarantees in the docs of > AtomicReferenceArray would kill it for me. You can't be sure how the > implementation will change over time. Does that include the guarantees that it provides indirectly, by reference to the package documentation? Patricia