Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!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 13:35:59 -0800 Organization: A noiseless patient Spider Lines: 10 Message-ID: References: <09848313-2372-4c23-8f52-fa84c612c100@u32g2000yqe.googlegroups.com> <15jRq.2104$d%2.1226@newsfe07.iad> <263caac2-6fba-46e2-a19e-9d414e08efe2@dp8g2000vbb.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 17 Jan 2012 21:36:01 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="XjIWM99mD7Ijfdu600oVPA"; logging-data="15718"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18pIh5BbgLL8W9vF7xIfcEwMV3UMzvteUo=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0 In-Reply-To: <263caac2-6fba-46e2-a19e-9d414e08efe2@dp8g2000vbb.googlegroups.com> Cancel-Lock: sha1:kLolQnEm+/CDVZZV2hJgz8bfY9E= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:11427 On 1/17/2012 12:38 PM, raphfrk@gmail.com wrote: > Thanks for the info. I think the conclusion is that it would be > unsafe? I will just use synchronized to ensure safety. Certainly my conclusion is that it is unsafe. "Synchronization" here includes use of volatiles. As long as you write the volatile last and read it first, the program is properly synchronized.