The OpenD Programming Language

Atomic.compareExchangeWeak

Atomically compares the atomic value with that of expected. If those are bitwise-equal, replaces the former with desired (performs read-modify-write operation). Otherwise, loads the actual atomic value stored into expected (performs load operation).

compare_exchange_weak is allowed to fail spuriously, that is, acts as if atomic value != expected even if they are equal. When a compare-and-exchange is in a loop, compare_exchange_weak will yield better performance on some platforms.

struct Atomic(T)
pure nothrow @nogc
bool
compareExchangeWeak
(
ref T expected
,)

Parameters

expected T

The expected value

desired T

The new desired value

Return Value

Type: bool

true if the underlying atomic value was successfully changed, false otherwise.

Meta