Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #10737
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe06.iad.POSTED!83aa503d!not-for-mail |
|---|---|
| From | Daniel Pitts <newsgroup.nospam@virtualinfinity.net> |
| User-Agent | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; 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> <jc5ffc$28s$1@dont-email.me> <ddkce71iqujhrsrslsca33a5nep023c4si@4ax.com> <9kodm9FfqrU1@mid.individual.net> <OsmdndL60tQimXrTnZ2dnUVZ_judnZ2d@posted.palinacquisition> <9ks8r2Fld4U1@mid.individual.net> |
| In-Reply-To | <9ks8r2Fld4U1@mid.individual.net> |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| Lines | 40 |
| Message-ID | <8m6Gq.201$Mw4.44@newsfe06.iad> (permalink) |
| X-Complaints-To | abuse@newsrazor.net |
| NNTP-Posting-Date | Wed, 14 Dec 2011 18:59:16 UTC |
| Date | Wed, 14 Dec 2011 10:59:15 -0800 |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:10737 |
Show key headers only | View raw
On 12/14/11 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? > >>>> In 32 bit, there is an assembler instruction cmpxchg8b designed to let >>>> 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.' The JLS does specifically say that volatile will ensure atomic operations on long and double. The last paragraph of section 17.7: "The load, store, read, and write actions on volatile variables are atomic, even if the type of the variable is double or long." <http://java.sun.com/docs/books/jls/second_edition/html/memory.doc.html#28330> So unless you use a non-conforming "JVM" implementation (which by definition isn't really a JVM), then you will *always* have atomic reads and atomic writes for volatile doubles and volatile longs.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Volatile keyword "raphfrk@gmail.com" <raphfrk@gmail.com> - 2011-12-12 04:51 -0800
Re: Volatile keyword Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-12-12 14:31 +0000
Re: Volatile keyword "raphfrk@gmail.com" <raphfrk@gmail.com> - 2011-12-12 06:52 -0800
Re: Volatile keyword Lew <lewbloch@gmail.com> - 2011-12-12 06:34 -0800
Re: Volatile keyword markspace <-@.> - 2011-12-12 10:00 -0800
Re: Volatile keyword Tom Anderson <twic@urchin.earth.li> - 2011-12-12 18:41 +0000
Re: Volatile keyword Patricia Shanahan <pats@acm.org> - 2011-12-12 11:43 -0800
Re: Volatile keyword Roedy Green <see_website@mindprod.com.invalid> - 2011-12-12 11:15 -0800
Re: Volatile keyword Robert Klemme <shortcutter@googlemail.com> - 2011-12-13 08:37 +0100
Re: Volatile keyword Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-12-12 23:54 -0800
Re: Volatile keyword Robert Klemme <shortcutter@googlemail.com> - 2011-12-14 19:39 +0100
Re: Volatile keyword Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-12-14 10:59 -0800
Re: Volatile keyword Patricia Shanahan <pats@acm.org> - 2011-12-14 11:00 -0800
Re: Volatile keyword Robert Klemme <shortcutter@googlemail.com> - 2011-12-14 22:35 +0100
Re: Volatile keyword Roedy Green <see_website@mindprod.com.invalid> - 2011-12-12 10:55 -0800
csiph-web