std
std.atomic
std.exception
std.intrinsic
std.memory
std.stdarg
std.thread
|
|
std.atomic
The atomic module is intended to provide some basic support for lock-free
concurrent programming. Some common operations are defined, each of which
may be performed using the specified memory barrier or a less granular
barrier if the hardware does not support the version requested. This
model is based on a design by Alexander Terekhov as outlined in
this thread.
Design Issues:
Originally, all functions were intended to be either static or non-static
members of the Atomic class. However, DMD currently can not disambiguate
between the two if they have the same name, so the current design was
chosen. This design also seems to be a bit more readable, so it may remain
even if the compiler bug (?) is fixed.
Future Directions:
As many architectures provide optimized atomic support for common integer
operations (such as increment, decrement, etc), these may be added in some
form--perhaps as additional global functions and in an AtomicValue type.
- enum msync;
- Memory synchronization flag. If the supplied option is not available on the
current platform then a stronger method will be used instead.
- hlb
- hoist-load barrier
- ddhlb
- hoist-load barrier with data-dependency "hint"
- hsb
- hoist-store barrier
- slb
- sink-load barrier
- ssb
- sink-store barrier
- acq
- hoist-load + hoist-store barrier
- rel
- sink-load + sink-store barrier
- none
- naked
- template atomicLoad(T,msync ms : cast(msync)7)
template atomicLoad(T,msync ms : cast(msync)0) template atomicLoad(T,msync ms : cast(msync)1) template atomicLoad(T,msync ms : cast(msync)5)
- Refreshes the contents of 'val' from main memory. This operation is both lock-free and atomic.
Returns:
The loaded value.
Params:
val |
The value to load. This value must be properly aligned. |
- template atomicStore(T,msync ms : cast(msync)7)
template atomicStore(T,msync ms : cast(msync)4) template atomicStore(T,msync ms : cast(msync)5) template atomicStore(T,msync ms : cast(msync)6)
- Stores 'newval' to the memory referenced by 'val'. This operation is both lock-free and atomic.
Params:
val |
The destination variable. |
newval |
The value to store. |
- template atomicStoreIf(T,msync ms : cast(msync)7)
template atomicStoreIf(T,msync ms : cast(msync)4) template atomicStoreIf(T,msync ms : cast(msync)5) template atomicStoreIf(T,msync ms : cast(msync)6)
- Stores 'newval' to the memory referenced by 'val' if val is equal to 'equalTo'. This operation
is both lock-free and atomic.
Returns:
true if the store occurred, false if not.
Params:
val |
The destination variable. |
newval |
The value to store. |
equalTo |
The comparison value. |
- struct Atomic;
- This class represents a value which will be subject to competing access. All accesses to
this value will be synchronized with main memory, and various memory barriers may be
employed for instruction ordering. Any primitive type of size equal to or smaller than
the memory bus size is allowed, so 32-bit machines may use values with size <= int.sizeof
and 64-bit machines may use values with size <= long.sizeof. The one exception to this
rule is that architectures that support DCAS will allow double-wide storeIf operations.
The 32-bit x86 architecture, for example, supports 64-bit storeIf operations.
- template load(msync ms : msync.none)
template load(msync ms : msync.hlb) template load(msync ms : msync.ddhlb) template load(msync ms : msync.acq)
- Refreshes the contents of this value from main memory. This operation is both lock-free and atomic.
Returns:
The loaded value.
- template store(msync ms : msync.none)
template store(msync ms : msync.ssb) template store(msync ms : msync.acq) template store(msync ms : msync.rel)
- Stores 'newval' to the memory referenced by this value. This operation is both lock-free and atomic.
Params:
newval |
The value to store. |
- template storeIf(msync ms : msync.none)
template storeIf(msync ms : msync.ssb) template storeIf(msync ms : msync.acq) template storeIf(msync ms : msync.rel)
- Stores 'newval' to the memory referenced by this value if val is equal to 'equalTo'. This operation
is both lock-free and atomic.
Returns:
true if the store occurred, false if not.
Params:
newval |
The value to store. |
equalTo |
The comparison value. |
|