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 14:41:40 -0800 Organization: A noiseless patient Spider Lines: 19 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 22:41:41 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="XjIWM99mD7Ijfdu600oVPA"; logging-data="7547"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Akf6U6DyJkQsRdrGljjXi4+YlCe79K20=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0 In-Reply-To: Cancel-Lock: sha1:4MUjA0zInhEPMPCK9D2/3wTExbI= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:11431 On 1/17/2012 1:35 PM, markspace wrote: > 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. Here's a video by the same guy, talking to the Seattle Java Users Group. Pay special attention to the "out of thin air guarantee."