Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.programmer Subject: Re: Volatile happens before question Date: Tue, 17 Jan 2012 16:14:52 -0800 Organization: A noiseless patient Spider Lines: 13 Message-ID: References: <09848313-2372-4c23-8f52-fa84c612c100@u32g2000yqe.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 18 Jan 2012 00:14:54 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="XjIWM99mD7Ijfdu600oVPA"; logging-data="9577"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195vXJ92yRvCstP4HPXlQkUMpHpDW5xcSw=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0 In-Reply-To: Cancel-Lock: sha1:MjmzOucuO2oo++AjyymrcwnNMAY= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:11439 On 1/17/2012 3:46 PM, Knute Johnson wrote: > And to quote Goetz "When a field is declared volatile, the compiler and > runtime are put on notice that this variable is shared and that > operations on it should not be reordered with other memory operations." To get that behavior, you have to actually read from the volatile after writing to it. Check the JLS. Both threads must participate in the happens-before operation, or this *is no* happens-before behavior.