Atomic¶
| Spice | |
|---|---|
Atomic<T> struct¶
A wrapper that guards a value of arbitrary type with a mutex, so it can be read and updated safely from multiple threads.
Constructors¶
ctor¶
| Spice | |
|---|---|
Construct an atomic initialized with the zero value of its type
ctor¶
| Spice | |
|---|---|
Construct an atomic initialized with the given value
Parameters
| Name | Type | Description |
|---|---|---|
value |
T |
Initial value |
Methods¶
store¶
| Spice | |
|---|---|
Atomically store a new value
Parameters
| Name | Type | Description |
|---|---|---|
value |
const T& |
Value to store |
load¶
| Spice | |
|---|---|
Atomically load the current value
Returns: const T& — Reference to the current value
exchange¶
| Spice | |
|---|---|
Atomically replace the value and return the previous one
Parameters
| Name | Type | Description |
|---|---|---|
value |
const T& |
New value to store |
Returns: T — Previous value
compareExchange¶
| Spice | |
|---|---|
Atomically set the value to desired only if it currently equals expected
Parameters
| Name | Type | Description |
|---|---|---|
expected |
const T& |
Value the atomic is compared against |
desired |
const T& |
Value to store if the comparison succeeds |
Returns: bool — true if the value was exchanged, false otherwise