Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #10668
| Newsgroups | comp.lang.java.programmer |
|---|---|
| From | Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> |
| Subject | Re: Volatile keyword |
| References | <41fa02ff-3f20-41bc-90d9-c3f7d3651fbf@n6g2000vbg.googlegroups.com> |
| Message-ID | <slrnjec426.fvg.avl@gamma.logic.tuwien.ac.at> (permalink) |
| Date | 2011-12-12 14:31 +0000 |
raphfrk@gmail.com <raphfrk@gmail.com> wrote: > Does this make all read/writes happen in full. That's how it is specified. > For example, if one thread had > volatile long a = 0xFFFFFFFF00000000L; > <do stuff> > a = ~a; > If another thread read a, would it always give 0xFFFFFFFF00000000 or > 0x00000000FFFFFFFF and not partial writes (say it updates 32 bits and > then the next 32 bits). That's how it is specified. :-) > I understand that if two threads do a++, it might only increment > twice, if they both read the old value at the same time. "once," but I think you meant "once," anyway, with "only" in the context. Even if more processes did "a = ~a;" concurrently on a volatile long a with given initialization, then the assumption of always reading either 0xFFFFFFFF00000000 or 0x00000000FFFFFFFF but nothing else would still be a rather safe bet. (i.e. betting only against hardware-flaws, or severe bugs in the JVM implementation) Of course, *which* one of these values you'd see is not necessarily related to the total number of these manipulations performed by all threads together (as in the a++ case). > Effectively, does the CPU lock the entire 64-bits for the long when > doing the write update, and so other threads either seen the updated > value or the old value? That's how it is specified. :-)
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