atom provides atomic operations for integers, floats, and strings.
create a new AtomicInt with an optional initial value
name | type | description |
---|---|---|
value |
int |
initial value, defaults to 0 |
basic
create a new AtomicInt with default value
load("atom", "new_int")
ai = new_int()
ai.inc()
print(ai.get())
# Output: 1
with value
create a new AtomicInt with a specific value
load("atom", "new_int")
ai = new_int(42)
ai.add(42)
print(ai.get())
# Output: 84
create a new AtomicFloat with an optional initial value
name | type | description |
---|---|---|
value |
float |
initial value, defaults to 0.0 |
basic
create a new AtomicFloat with default value
load("atom", "new_float")
af = new_float()
print(af.get())
# Output: 0.0
with value
create a new AtomicFloat with a specific value
load("atom", "new_float")
af = new_float(3.14)
print(af.get())
# Output: 3.14
create a new AtomicString with an optional initial value
name | type | description |
---|---|---|
value |
string |
initial value, defaults to an empty string |
basic
create a new AtomicString with default value
load("atom", "new_string")
as = new_string()
print(as.get()) # Output: ""
with value
create a new AtomicString with a specific value
load("atom", "new_string")
as = new_string("hello")
print(as.get())
# Output: "hello"
an atomic integer type with various atomic operations
Methods
returns the current value
sets the value
compares and swaps the value if it matches old
adds delta to the value and returns the new value
subtracts delta from the value and returns the new value
increments the value by 1 and returns the new value
decrements the value by 1 and returns the new value
an atomic float type with various atomic operations
Methods
returns the current value
sets the value
compares and swaps the value if it matches old
adds delta to the value and returns the new value
subtracts delta from the value and returns the new value
an atomic string type with various atomic operations
Methods
returns the current value
sets the value
compares and swaps the value if it matches old