Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder5.news.weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.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: Question whether a problem with race conditions exists in this case Date: Wed, 14 Dec 2011 14:13:41 -0800 Organization: A noiseless patient Spider Lines: 25 Message-ID: References: <8bbbbee3-adcc-4f28-aff5-2e230b047401@u6g2000vbg.googlegroups.com> <31419376.376.1323889493017.JavaMail.geo-discussion-forums@prmw6> <1e0613c1-9248-4f1d-a5e1-65f08aa31c0f@y18g2000yqy.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 14 Dec 2011 22:13:44 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="XjIWM99mD7Ijfdu600oVPA"; logging-data="19488"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/6wp5A76y1mNrXGlgkI+rCja5tJXVkIvE=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0 In-Reply-To: <1e0613c1-9248-4f1d-a5e1-65f08aa31c0f@y18g2000yqy.googlegroups.com> Cancel-Lock: sha1:UbnmmXgo7izS1t6GgU1agteY2oY= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:10750 On 12/14/2011 12:32 PM, Saxo wrote: > This way the single AtomicBoolean object is passed that will be > changed from false to true by reference, so that all new values > become visible for any thread calling aNode.get() "at once". > But there isn't a single AtomicBoolean, and it isn't passed in. It's assigned as an instance variable initialization. There's one AtomicBoolean per Node object. This is really important, because it makes your whole code wrong. If you want to pass something in, then pass it in. public class Node { private final AtomicBoolean useNewValue; public Node( AtomicBoolean commonFlag ) { useNewValue = commonFlag; } ... }