Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: Volatile keyword Date: Wed, 14 Dec 2011 19:39:30 +0100 Lines: 35 Message-ID: <9ks8r2Fld4U1@mid.individual.net> References: <41fa02ff-3f20-41bc-90d9-c3f7d3651fbf@n6g2000vbg.googlegroups.com> <9kodm9FfqrU1@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: individual.net K40fn1cGHQdIQKye593l3g/P+BDbq/YPJp4DPJvKfF2FG9+yA= Cancel-Lock: sha1:PcXkkwC9mubN328FyxRXS71RxME= User-Agent: Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20111124 Thunderbird/8.0 In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:10733 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 (=C2=A717.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=20 provide reference to the JLS so everybody can check it? >>> In 32 bit, there is an assembler instruction cmpxchg8b designed to le= t >>> you implement a light weight atomic 64-bit read. >> >> Since you do not know on what JVM your Java program will run when you >> write it (or at least someone can choose to use a different JVM model)= >> it is safer to code under the assumption that a long and double write = is >> two operations i.e. not atomic. > > There is no need to make that assumption provided the field involved is= > marked "volatile". I beg to differ - but I am eagerly waiting to be convinced otherwise. Cheers robert