[concurrency-interest] Unsynchronized lazy conditions

Viktor Klang viktor.klang at gmail.com
Thu May 31 05:51:14 EDT 2018


On Thu, May 31, 2018 at 11:26 AM, Aleksey Shipilev <shade at redhat.com> wrote:

> On 05/31/2018 11:22 AM, Viktor Klang wrote:
> > Aleksey's suggestion(s) is/are definitely cleaner than mine:
> >
> > Depending on performance requirements the following might be cheaper,
> > of course assuming you can type-wise hide the AtomicBoolean inheritance
> from consumer code:
> >
> > class Foo extends AtomicBoolean { // No indirection due to the
> allocation of AtomicBoolean
> >    public void run() {
> >      if (!get() && !getAndSet(true)) { // LOCK XCHG instead of LOCK
> CMPXCHG
> >        LOG.warn("Warning");
> >      }
> >    }
> > }
>
> Or that. I don't think we care about getAndSet vs compareAndSet all that
> much, since it is one-off
> thing. The important thing is the first fast-path check.
>

Agreed. The difference in the first case is most likely eclipsed by the
cost of the logging call. And contention for the first invocation is likely
non-existant.


>
> Thanks,
> -Aleksey
>
>


-- 
Cheers,
√
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20180531/e59eeda0/attachment-0001.html>


More information about the Concurrency-interest mailing list