AtomicBoolean
open class AtomicBoolean : Serializable
kotlin.Any | |
↳ | java.util.concurrent.atomic.AtomicBoolean |
A boolean
value that may be updated atomically. See the VarHandle
specification for descriptions of the properties of atomic accesses. An AtomicBoolean
is used in applications such as atomically updated flags, and cannot be used as a replacement for a java.lang.Boolean
.
Summary
Public constructors | |
---|---|
Creates a new |
|
AtomicBoolean(initialValue: Boolean) Creates a new |
Public methods | |
---|---|
Boolean |
compareAndExchange(expectedValue: Boolean, newValue: Boolean) Atomically sets the value to |
Boolean |
compareAndExchangeAcquire(expectedValue: Boolean, newValue: Boolean) Atomically sets the value to |
Boolean |
compareAndExchangeRelease(expectedValue: Boolean, newValue: Boolean) Atomically sets the value to |
Boolean |
compareAndSet(expectedValue: Boolean, newValue: Boolean) Atomically sets the value to |
Boolean |
get() Returns the current value, with memory effects as specified by |
Boolean |
Returns the current value, with memory effects as specified by |
Boolean |
Atomically sets the value to |
Boolean |
Returns the current value, with memory effects as specified by |
Boolean |
getPlain() Returns the current value, with memory semantics of reading as if the variable was declared non- |
Unit |
Sets the value to |
Unit |
Sets the value to |
Unit |
Sets the value to |
Unit |
Sets the value to |
Unit |
setRelease(newValue: Boolean) Sets the value to |
open String |
toString() Returns the String representation of the current value. |
open Boolean |
weakCompareAndSet(expectedValue: Boolean, newValue: Boolean) Possibly atomically sets the value to |
Boolean |
weakCompareAndSetAcquire(expectedValue: Boolean, newValue: Boolean) Possibly atomically sets the value to |
open Boolean |
weakCompareAndSetPlain(expectedValue: Boolean, newValue: Boolean) Possibly atomically sets the value to |
Boolean |
weakCompareAndSetRelease(expectedValue: Boolean, newValue: Boolean) Possibly atomically sets the value to |
Boolean |
weakCompareAndSetVolatile(expectedValue: Boolean, newValue: Boolean) Possibly atomically sets the value to |
Public constructors
AtomicBoolean
AtomicBoolean()
Creates a new AtomicBoolean
with initial value false
.
AtomicBoolean
AtomicBoolean(initialValue: Boolean)
Creates a new AtomicBoolean
with the given initial value.
Parameters | |
---|---|
initialValue |
Boolean: the initial value |
Public methods
compareAndExchange
fun compareAndExchange(
expectedValue: Boolean,
newValue: Boolean
): Boolean
Atomically sets the value to newValue
if the current value, referred to as the witness value, == expectedValue
, with memory effects as specified by VarHandle.compareAndExchange
.
Parameters | |
---|---|
expectedValue |
Boolean: the expected value |
newValue |
Boolean: the new value |
Return | |
---|---|
Boolean |
the witness value, which will be the same as the expected value if successful |
compareAndExchangeAcquire
fun compareAndExchangeAcquire(
expectedValue: Boolean,
newValue: Boolean
): Boolean
Atomically sets the value to newValue
if the current value, referred to as the witness value, == expectedValue
, with memory effects as specified by VarHandle.compareAndExchangeAcquire
.
Parameters | |
---|---|
expectedValue |
Boolean: the expected value |
newValue |
Boolean: the new value |
Return | |
---|---|
Boolean |
the witness value, which will be the same as the expected value if successful |
compareAndExchangeRelease
fun compareAndExchangeRelease(
expectedValue: Boolean,
newValue: Boolean
): Boolean
Atomically sets the value to newValue
if the current value, referred to as the witness value, == expectedValue
, with memory effects as specified by VarHandle.compareAndExchangeRelease
.
Parameters | |
---|---|
expectedValue |
Boolean: the expected value |
newValue |
Boolean: the new value |
Return | |
---|---|
Boolean |
the witness value, which will be the same as the expected value if successful |
compareAndSet
fun compareAndSet(
expectedValue: Boolean,
newValue: Boolean
): Boolean
Atomically sets the value to newValue
if the current value == expectedValue
, with memory effects as specified by VarHandle.compareAndSet
.
Parameters | |
---|---|
expectedValue |
Boolean: the expected value |
newValue |
Boolean: the new value |
Return | |
---|---|
Boolean |
true if successful. False return indicates that the actual value was not equal to the expected value. |
get
fun get(): Boolean
Returns the current value, with memory effects as specified by VarHandle.getVolatile
.
Return | |
---|---|
Boolean |
the current value |
getAcquire
fun getAcquire(): Boolean
Returns the current value, with memory effects as specified by VarHandle.getAcquire
.
Return | |
---|---|
Boolean |
the value |
getAndSet
fun getAndSet(newValue: Boolean): Boolean
Atomically sets the value to newValue
and returns the old value, with memory effects as specified by VarHandle.getAndSet
.
Parameters | |
---|---|
newValue |
Boolean: the new value |
Return | |
---|---|
Boolean |
the previous value |
getOpaque
fun getOpaque(): Boolean
Returns the current value, with memory effects as specified by VarHandle.getOpaque
.
Return | |
---|---|
Boolean |
the value |
getPlain
fun getPlain(): Boolean
Returns the current value, with memory semantics of reading as if the variable was declared non-volatile
.
Return | |
---|---|
Boolean |
the value |
lazySet
fun lazySet(newValue: Boolean): Unit
Sets the value to newValue
, with memory effects as specified by VarHandle.setRelease
.
Parameters | |
---|---|
newValue |
Boolean: the new value |
set
fun set(newValue: Boolean): Unit
Sets the value to newValue
, with memory effects as specified by VarHandle.setVolatile
.
Parameters | |
---|---|
newValue |
Boolean: the new value |
setOpaque
fun setOpaque(newValue: Boolean): Unit
Sets the value to newValue
, with memory effects as specified by VarHandle.setOpaque
.
Parameters | |
---|---|
newValue |
Boolean: the new value |
setPlain
fun setPlain(newValue: Boolean): Unit
Sets the value to newValue
, with memory semantics of setting as if the variable was declared non-volatile
and non-final
.
Parameters | |
---|---|
newValue |
Boolean: the new value |
setRelease
fun setRelease(newValue: Boolean): Unit
Sets the value to newValue
, with memory effects as specified by VarHandle.setRelease
.
Parameters | |
---|---|
newValue |
Boolean: the new value |
toString
open fun toString(): String
Returns the String representation of the current value.
Return | |
---|---|
String |
the String representation of the current value |
weakCompareAndSet
open funweakCompareAndSet(
expectedValue: Boolean,
newValue: Boolean
): Boolean
Deprecated: This method has plain memory effects but the method name implies volatile memory effects (see methods such as compareAndExchange
and compareAndSet
). To avoid confusion over plain or volatile memory effects it is recommended that the method weakCompareAndSetPlain
be used instead.
Possibly atomically sets the value to newValue
if the current value == expectedValue
, with memory effects as specified by VarHandle.weakCompareAndSetPlain
.
Parameters | |
---|---|
expectedValue |
Boolean: the expected value |
newValue |
Boolean: the new value |
Return | |
---|---|
Boolean |
true if successful |
See Also
weakCompareAndSetAcquire
fun weakCompareAndSetAcquire(
expectedValue: Boolean,
newValue: Boolean
): Boolean
Possibly atomically sets the value to newValue
if the current value == expectedValue
, with memory effects as specified by VarHandle.weakCompareAndSetAcquire
.
Parameters | |
---|---|
expectedValue |
Boolean: the expected value |
newValue |
Boolean: the new value |
Return | |
---|---|
Boolean |
true if successful |
weakCompareAndSetPlain
open fun weakCompareAndSetPlain(
expectedValue: Boolean,
newValue: Boolean
): Boolean
Possibly atomically sets the value to newValue
if the current value == expectedValue
, with memory effects as specified by VarHandle.weakCompareAndSetPlain
.
Parameters | |
---|---|
expectedValue |
Boolean: the expected value |
newValue |
Boolean: the new value |
Return | |
---|---|
Boolean |
true if successful |
weakCompareAndSetRelease
fun weakCompareAndSetRelease(
expectedValue: Boolean,
newValue: Boolean
): Boolean
Possibly atomically sets the value to newValue
if the current value == expectedValue
, with memory effects as specified by VarHandle.weakCompareAndSetRelease
.
Parameters | |
---|---|
expectedValue |
Boolean: the expected value |
newValue |
Boolean: the new value |
Return | |
---|---|
Boolean |
true if successful |
weakCompareAndSetVolatile
fun weakCompareAndSetVolatile(
expectedValue: Boolean,
newValue: Boolean
): Boolean
Possibly atomically sets the value to newValue
if the current value == expectedValue
, with memory effects as specified by VarHandle.weakCompareAndSet
.
Parameters | |
---|---|
expectedValue |
Boolean: the expected value |
newValue |
Boolean: the new value |
Return | |
---|---|
Boolean |
true if successful |