Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: Volatile happens before question Date: Fri, 20 Jan 2012 11:12:00 -0800 Organization: albasani.net Lines: 48 Message-ID: References: <09848313-2372-4c23-8f52-fa84c612c100@u32g2000yqe.googlegroups.com> <726da9ce-57f4-4136-b50b-56a032aca196@f1g2000yqi.googlegroups.com> <652cb878-fb2f-4361-8f70-61bc493cebf6@r16g2000yqi.googlegroups.com> <6280ea10-c656-40fa-ba3d-50f24d471978@j15g2000yqb.googlegroups.com> <6b44805b-ff63-41ba-8060-cbd92164f9d6@o9g2000yqa.googlegroups.com> <240ac224-9713-4931-89f6-aeb7578aee09@m11g2000yqe.googlegroups.com> <5ff9ba43-a357-4c0b-9c26-0a90242884d5@m11g2000yqe.googlegroups.com> <626c6bb6-103f-4b89-8484-316641c0476c@18g2000yqe.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net nzASQvKdizqsMr5jwyTAG9KvinUSUO5KGOxZNYOg9jEDQ/TVrpvXHb3CIX4Tl/8cj8Ln+vJ+HaRorphsY6hhULIzvjewrL+sl7y4XMKuHiRhSZM5S++xQN37N4NzUQUb NNTP-Posting-Date: Fri, 20 Jan 2012 19:12:02 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="JuCWkOQ2C8FAQdA3ORUTicDQH9wTmJa/LKuf86Zex2I32vmMrQ3WVR2YjvuvFvmZDU/MMPXLhsPTfvL8BwlrUUFk+uiMeQbk6Euu+dnTXguLZykCcYqjab5pgOICRfKz"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111124 Thunderbird/8.0 In-Reply-To: Cancel-Lock: sha1:/3XI0SaKSaebehF0ZG+2O0a2HVw= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:11527 markspace wrote: > raphfrk@gmail.com wrote: >> The issue is that a read of the old value doesn't guarantee that no >> update has happened. > ... >> Even though WA happens after RB in the synchronization ordering, >> there is no relationship between R-read and W-write. The reason is >> that WA and RB have no happens-before relationship. > > > I don't think this is quite correct. No update is in progress in your trace. There is no happens-before between what raphfrk marked as "R-read" and "W-write". He is quite correct. > What I think they're talking about is causality, or the idea that map.get() No, about visibility. > might see a write from the future. That is, a write from the map.put(). I > don't see anywhere in the JLS where it says that reads can't be reordered > across this type memory barrier. That's not different from what raphfrk said. > I'll have to dig out JCIP since at this point I think trying to read the math > heavy sections of the JLS have defeated me. The read from the future thing > kinda makes sense, since I don't recall anything that prevents it. Maybe there > is though... > > Note I already mentioned this about 4 posts ago... ;-) When there are more than one read and more than one write, you have to look at the entire picture. Many in this conversation have made the mistake of looking at only the first of a series of reads or writes and trying to reason about the visible value, while ignoring later, possibly reordered actions. Bottom line - the read from thread 2 (T2) before the write to a volatile in T1 does not impose a happens-before ("/hb/" or "<") between those two actions. Does not. All bets are off. Done. If the T2 read follows a different T1 write with which there is a /hb/ relationship that's a red herring. -- Lew Honi soit qui mal y pense. http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg