Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: Question whether a problem with race conditions exists in this case Date: Wed, 14 Dec 2011 16:55:51 -0800 (PST) Organization: http://groups.google.com Lines: 28 Message-ID: <23351706.113.1323910551821.JavaMail.geo-discussion-forums@yqkb10> References: <8bbbbee3-adcc-4f28-aff5-2e230b047401@u6g2000vbg.googlegroups.com> Reply-To: comp.lang.java.programmer@googlegroups.com NNTP-Posting-Host: 173.164.137.214 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1323910649 20750 127.0.0.1 (15 Dec 2011 00:57:29 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 15 Dec 2011 00:57:29 +0000 (UTC) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=173.164.137.214; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T User-Agent: G2/1.0 X-Google-Web-Client: true Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:10760 Saxo wrote: >> =A0 =A0 =A0When you change the shared AtomicBoolean, some threads execut= ing >> get() may have already observed the old value and may have decided >> which value to return based on that now-outdated observation. =A0So yes, >> there's a race: It is possible for get() to return an old value after >> the AtomicBoolean changes from true to false, or a new value after it >> changes from false to true. >=20 > Oh shit, of course! I have thought about it. First though was to call >=20 > if(useNewValue.get()) { > // ... > } >=20 > that often till it returns the same value. But useNewValue could > change just thereafter. So you would have to call this infinitely > often till you are sure you get the right value. Obviously, this > doesn't work. Then I forgot about the issue. >=20 > Thanks for the hint. Now I have to think how to solve this ... Bearing in mind that you don't need, and shouldn't use, an 'AtomicBoolean' = for this in the first place. --=20 Lew