Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.42!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!74.125.46.80.MISMATCH!postnews.google.com!news2.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Wed, 18 Jan 2012 21:04:04 -0600 Date: Wed, 18 Jan 2012 19:03:57 -0800 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Volatile happens before question References: <09848313-2372-4c23-8f52-fa84c612c100@u32g2000yqe.googlegroups.com> <1pi7kea3zdo0b.1ixhuq3p9ybbu$.dlg@40tude.net> <60dddbf9-3686-4824-a918-64a59faba177@a8g2000vba.googlegroups.com> <726da9ce-57f4-4136-b50b-56a032aca196@f1g2000yqi.googlegroups.com> <652cb878-fb2f-4361-8f70-61bc493cebf6@r16g2000yqi.googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <_IGdnREOZNS5FYrSnZ2dnUVZ_tudnZ2d@earthlink.com> Lines: 72 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 75.11.53.36 X-Trace: sv3-GH469NZJ0FfQpFbMDhAHksRC6bLYr/uJ+KaDK41FCP9zDJu9UH55YmpWlBgZDJaSm0fE6jfuoS4pCqR!/ttn8L5mnmP1iaEMS2oZYujMJOAs7P7ywRcwclq1xwNVhSPXs+X+Oq927miCAq1mezsxALiPPVNI!R/oqySmm4fKH4WJtDLNX8+4kgVqxbc9CbmheKt++Anc= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 4331 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:11487 On 1/18/2012 5:17 PM, markspace wrote: > On 1/18/2012 4:34 PM, Patricia Shanahan wrote: >> >> I'm curious about the "values out of thin air" statement about hardware. >> Could you give some information about how it happens? > > > > > If I understand correctly: > > x & y are global integers initialized to 0. r1 and r2 are temporary > variables. > > Thread 1: > > int r1 = x; > y = r1; > > Thread 2: > > int r2 = y; > x = r2; > > > What happens is during the read of x, it is not found in cache. So a bus > cycle is started to read the value of x, but at the same time the cpu > has nothing to do while waiting, so it speculates as to the value of x > and continues processing. Let's say the cpu speculates that x is 42. > > r1 = 42; > > Now since r1 is 42, when y is written it also gets a speculative write > of the value 42; > > y = 42; > > This doesn't actually go on the memory bus, it's held in an output queue > of writes. > > Next, Thread 2 comes along and also tries to read y. It also can't and > like thread 1 decides to speculate on the value of y while waiting for > main memory. It speculates y is 42. > > r2 = 42; > > Next x is written from the value of r2. > > x = 42; > > At this point, the internal cpu bus sees a write of 42 to the memory > location of x and thinks its speculation was correct, cancels the memory > read, and commits the value of y to memory. > > That's what I understood from that talk on Vimeo. I'm starting to wonder > though exactly what sort of problem Bartosz Milewski is describing > there. I thought he was describing what could actually happen in the > absence of synchronization; possibly he is speculating on some kind of > hardware issue however. > That looks to me like a straight bug in the speculative processing implementation. The books and papers I've read on the subject, going back to some of the earliest supercomputers, all emphasize bookkeeping to ensure that speculative results are known to be speculative, and not sent to the bus or used in other threads until they are committed. I'm not saying that no processor could possibly have such a bug, but I would be surprised it it existed. Patricia