Methods Summary |
---|
public final boolean | compareAndSet(boolean expect, boolean update)Atomically sets the value to the given update value if the
current value is equal to the expected value. Any given
invocation of this operation may fail (return
false) spuriously, but repeated invocation when
the current value holds the expected value and no other thread
is also attempting to set the value will eventually succeed.
int e = expect ? 1 : 0;
int u = update ? 1 : 0;
return unsafe.compareAndSwapInt(this, valueOffset, e, u);
|
public final boolean | get()Returns the current value.
return value != 0;
|
public final boolean | getAndSet(boolean newValue)Sets to the given value and returns the previous value.
for (;;) {
boolean current = get();
if (compareAndSet(current, newValue))
return current;
}
|
public final void | set(boolean newValue)Unconditionally sets to the given value.
value = newValue ? 1 : 0;
|
public java.lang.String | toString()Returns the String representation of the current value.
return Boolean.toString(get());
|
public boolean | weakCompareAndSet(boolean expect, boolean update)Atomically set the value to the given updated value
if the current value == the expected value.
May fail spuriously.
int e = expect ? 1 : 0;
int u = update ? 1 : 0;
return unsafe.compareAndSwapInt(this, valueOffset, e, u);
|