Say you have:
volatile boolean called = false;
Is this
if ( !called && (called = true) ) { ... do once ... }
an atomic operation?
I know about AtomicBoolean. The question is not about that so try to resist your urges.
Say you have:
volatile boolean called = false;
Is this
if ( !called && (called = true) ) { ... do once ... }
an atomic operation?
I know about AtomicBoolean. The question is not about that so try to resist your urges.
In a naive implementation this could boil down to:
LOAD A ; called
NEG ; negate
BRF 1$ ; branch if false
LOAD 1 ; true
STOR A ; store into called
1$: ; do once
Not exactly atomic, is it? The Java compiler probably changes the NEG/BRF sequence to BRT (branch if true), but that's about as much help as you can rationally expect.
Strange question.