[concurrency-interest] Unsynchronized lazy conditions

Aleksey Shipilev shade at redhat.com
Thu May 31 05:26:03 EDT 2018

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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20180531/dc59255b/attachment.sig>

More information about the Concurrency-interest mailing list