| 1 | module main |
| 2 | |
| 3 | import x.atomics |
| 4 | |
| 5 | fn main() { |
| 6 | // Basic atomic load and store operations |
| 7 | mut value := i32(0) |
| 8 | |
| 9 | // Atomically store a value |
| 10 | atomics.store_i32(&value, 42) |
| 11 | |
| 12 | // Atomically load the value |
| 13 | loaded := atomics.load_i32(&value) |
| 14 | println('Loaded value: ${loaded}') // Output: 42 |
| 15 | |
| 16 | // Atomic add: returns the new value after addition |
| 17 | new_value := atomics.add_i32(&value, 10) |
| 18 | println('After add: ${new_value}') // Output: 52 |
| 19 | |
| 20 | // Atomic swap: returns the old value |
| 21 | old := atomics.swap_i32(&value, 100) |
| 22 | println('Old value: ${old}, new value: ${atomics.load_i32(&value)}') // Output: 52, 100 |
| 23 | } |
| 24 | |