Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!goblin2!goblin.stu.neva.ru!feeder2.cambriumusenet.nl!feeder1.cambriumusenet.nl!feed.tweaknews.nl!postnews.google.com!news1.google.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: Wed, 14 Dec 2011 13:00:55 -0600 Date: Wed, 14 Dec 2011 11:00:50 -0800 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Volatile keyword References: <41fa02ff-3f20-41bc-90d9-c3f7d3651fbf@n6g2000vbg.googlegroups.com> <9kodm9FfqrU1@mid.individual.net> <9ks8r2Fld4U1@mid.individual.net> In-Reply-To: <9ks8r2Fld4U1@mid.individual.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Message-ID: Lines: 31 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 70.230.194.31 X-Trace: sv3-KruAmKINwi+npVM8b7vS8rjFRsqKC8LQLOQ/UEogORFIwD9//ZHFO3G0RFHo1tzwn22OsolDBRYmosX!8u46WAcRkGKT4PFHe3+9mv8r7B3DHnSlJSbPGO3r8ZhKqdGAa1CPMO36EwMJcp6eZKGOs5mEx+Kr!r8ZWjUG2/u4gZNEPeEfjWl+SEWiYgACYXIxMUF+bRV8tEQ== 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: 2833 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:10738 On 12/14/2011 10:39 AM, Robert Klemme wrote: > On 12/13/2011 08:54 AM, Peter Duniho wrote: >> On 12/12/11 11:37 PM, Robert Klemme wrote: >>> [...]Bottom line is that the JVM spec does not make >>> any guarantees here (ยง17.7 see Lew's reference). >> >> I think it's worth being careful about "does not make any guarantees >> here". The implication of 17.7 is that there _is_ in fact a guarantee, >> for certain 64-bit fields marked as "volatile". Specifically, those >> which are of the type "double" or "long". This is true even on 32-bit >> systems. > > And what guarantee is there? Can you unambiguously formulate that and > provide reference to the JLS so everybody can check it? As indicated in the quoted material, the relevant section is "17.7 Non-atomic Treatment of double and long" http://java.sun.com/docs/books/jls/third_edition/html/memory.html#61803 The key paragraph, for this purpose, says: "For the purposes of the Java programming language memory model, a single write to a non-volatile long or double value is treated as two separate writes: one to each 32-bit half. This can result in a situation where a thread sees the first 32 bits of a 64 bit value from one write, and the second 32 bits from another write. Writes and reads of volatile long and double values are always atomic. Writes to and reads of references are always atomic, regardless of whether they are implemented as 32 or 64 bit values." Patricia