View source code
Display the source code in core/atomic.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Template core.atomic.cas

Performs either compare-and-set or compare-and-swap (or exchange).

template cas(MemoryOrder succ = MemoryOrder.seq, MemoryOrder fail = MemoryOrder.seq) ;

There are two categories of overloads in this template: the first one does a simple compare-and-set, and returns a boolean if the operation happened. The value this is written (writeThis) can be an rvalue. the second category does a compare-and-swap, or compare-and-exchange, and expects writeThis to be a pointer type, where the previous value of here will be written.

This operation is both lock-free and atomic.

Contained Functions

NameDescription
cas Compare-and-set for non-shared values
cas Compare-and-set for shared value type
cas Compare-and-set for shared reference type (class)
cas Compare-and-exchange for non-shared types
cas Compare and exchange for mixed-sharedness types
cas Compare-and-exchange for class

Parameters

NameDescription
here The address of the destination variable.
writeThis The value to store.
ifThis The comparison value.

Returns

true if the store occurred, false if not.

Authors

Sean Kelly, Alex Rønne Petersen, Manu Evans

License

Boost License 1.0