Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: Volatile keyword Date: Mon, 12 Dec 2011 06:34:18 -0800 (PST) Organization: http://groups.google.com Lines: 28 Message-ID: <22507025.2260.1323700458271.JavaMail.geo-discussion-forums@prcx11> References: <41fa02ff-3f20-41bc-90d9-c3f7d3651fbf@n6g2000vbg.googlegroups.com> Reply-To: comp.lang.java.programmer@googlegroups.com NNTP-Posting-Host: 173.164.137.214 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1323700458 11164 127.0.0.1 (12 Dec 2011 14:34:18 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 12 Dec 2011 14:34:18 +0000 (UTC) In-Reply-To: <41fa02ff-3f20-41bc-90d9-c3f7d3651fbf@n6g2000vbg.googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=173.164.137.214; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T User-Agent: G2/1.0 X-Google-Web-Client: true Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:10669 On Monday, December 12, 2011 4:51:41 AM UTC-8, rap...@gmail.com wrote: > Does this make all read/writes happen in full. > > For example, if one thread had > > volatile long a = 0xFFFFFFFF00000000L; > > > > 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). > > I understand that if two threads do a++, it might only increment > twice, if they both read the old value at the same time. > > 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? http://java.sun.com/docs/books/jls/third_edition/html/memory.html#17.4 http://java.sun.com/docs/books/jls/third_edition/html/memory.html#17.7 http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.3.1.4 -- Lew