std
std.array
std.atomic
std.bitarray
std.exception
std.intrinsic
std.memory
std.regexp
std.thread
std.traits
std.unicode
std.vararg
std.math.core
std.math.ieee
std.math.special
|
|
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 isValidAtomicType(T)
- template isValidNumericType(T)
- template isHoistOp(msync ms)
- template isSinkOp(msync ms)
- template atomicValueIsProperlyAligned(T)
- template doAtomicLoad(bool membar,T)
- template doAtomicStore(bool membar,T)
- template doAtomicStoreIf(bool membar,T)
- template doAtomicIncrement(bool membar,T)
- template doAtomicDecrement(bool membar,T)
- template atomicLoad(msync ms : cast(msync)7,T)
template atomicLoad(msync ms : cast(msync)0,T) template atomicLoad(msync ms : cast(msync)1,T) template atomicLoad(msync ms : cast(msync)5,T)
- 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(msync ms : cast(msync)7,T)
template atomicStore(msync ms : cast(msync)4,T) template atomicStore(msync ms : cast(msync)5,T) template atomicStore(msync ms : cast(msync)6,T)
- 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(msync ms : cast(msync)7,T)
template atomicStoreIf(msync ms : cast(msync)4,T) template atomicStoreIf(msync ms : cast(msync)5,T) template atomicStoreIf(msync ms : cast(msync)6,T)
- 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. |
- template atomicIncrement(msync ms : cast(msync)7,T)
template atomicIncrement(msync ms : cast(msync)4,T) template atomicIncrement(msync ms : cast(msync)5,T) template atomicIncrement(msync ms : cast(msync)6,T)
- This operation is only legal for built-in value and pointer types, and is equivalent to an atomic
"val = val + 1" operation. This function exists to facilitate use of the optimized increment
instructions provided by some architecures. If no such instruction exists on the target platform
then the behavior will perform the operation using more traditional means. This operation is both
lock-free and atomic.
Returns:
The result of an atomicLoad of val immediately following the increment operation. This value
is not required to be equal to the newly stored value. Thus, competing writes are allowed to
occur between the increment and successive load operation.
Params:
val |
The value to increment. |
- template atomicDecrement(msync ms : cast(msync)7,T)
template atomicDecrement(msync ms : cast(msync)4,T) template atomicDecrement(msync ms : cast(msync)5,T) template atomicDecrement(msync ms : cast(msync)6,T)
- This operation is only legal for built-in value and pointer types, and is equivalent to an atomic
"val = val - 1" operation. This function exists to facilitate use of the optimized decrement
instructions provided by some architecures. If no such instruction exists on the target platform
then the behavior will perform the operation using more traditional means. This operation is both
lock-free and atomic.
Returns:
The result of an atomicLoad of val immediately following the increment operation. This value
is not required to be equal to the newly stored value. Thus, competing writes are allowed to
occur between the increment and successive load operation.
Params:
val |
The value to decrement. |
- 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. |
- template testLoad(msync ms,T)
- template testStore(msync ms,T)
- template testStoreIf(msync ms,T)
- template testIncrement(msync ms,T)
- template testDecrement(msync ms,T)
- template testType(T)
|