Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Knute Johnson Newsgroups: comp.lang.java.programmer Subject: Re: Volatile happens before question Date: Tue, 17 Jan 2012 20:01:08 -0800 Organization: A noiseless patient Spider Lines: 17 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 04:01:08 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="mz/LDSJwiWnk3Jnnqg7x+Q"; logging-data="31242"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19vLJsDdw26tEE41VRIkZTP" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:9.0) Gecko/20111222 Thunderbird/9.0.1 In-Reply-To: Cancel-Lock: sha1:MQkOcyma3mLdOwm/51AjmWGT2aM= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:11450 On 1/17/2012 4:14 PM, markspace wrote: > 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. Assigning a value to a is a write. Using it in the if test is a read. -- Knute Johnson