Quantcast
Channel: Atomic compareAndSet but with callback? - Stack Overflow
Browsing latest articles
Browse All 5 View Live

Answer by Delark for Atomic compareAndSet but with callback?

I know this is old, but I've found there is no perfect way to achieve this, more specifically this:trying to find a less error prone way to guard code in a "do (anything) once..."I'll add to this...

View Article



Answer by Holger for Atomic compareAndSet but with callback?

You’re over-complicating things. Just because there are now lambda expression, you don’t need to solve everything with lambdas:private volatile boolean initialized;…if(!initialized) synchronized(this)...

View Article

Answer by the8472 for Atomic compareAndSet but with callback?

guard code in a "do once for object"how exactly to implement that depends on what you want other threads attempting to execute the same thing in the meantime. if you just let them run past the CAS they...

View Article

Answer by JB Nizet for Atomic compareAndSet but with callback?

compareAndSet returns true if the update was done, and false if the actual value was not equal to the expected value. So just use if (ref.compareAndSet(expectedValue, newValue)) { ... }That said, I...

View Article

Atomic compareAndSet but with callback?

I know that AtomicReference has compareAndSet, but I feel like what I want to do is thisprivate final AtomicReference<Boolean> initialized = new AtomicReference<>( false...

View Article

Browsing latest articles
Browse All 5 View Live




Latest Images