Skip to content

Commit e3f69bc

Browse files
committed
Bump minor version.
1 parent c0be77d commit e3f69bc

4 files changed

Lines changed: 40 additions & 9 deletions

File tree

context/getting-started.md

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ $ bundle add io-buffer-atomic
1414

1515
`io-buffer-atomic` extends `IO::Buffer` with atomic operations that are safe for concurrent access across threads and processes. When multiple threads or processes share memory (via `IO::Buffer`), you need atomic operations to prevent race conditions and ensure data consistency.
1616

17+
**Important**: Atomic operations work on raw memory bytes in host endian (native byte order). Both `:u32` and `:U32` map to the same atomic operation since they operate on the same raw memory bytes. The endianness distinction only affects how Ruby's `get_value`/`set_value` interpret bytes, not atomic operations.
18+
1719
Use atomic operations when you need:
1820
- **Thread-safe counters**: Multiple threads updating shared counters without locks.
1921
- **Process-safe coordination**: Multiple processes coordinating via shared memory.
@@ -77,6 +79,38 @@ result = buffer.atomic_xor(:u32, 0, 0b1111)
7779
# => 0b0000
7880
```
7981

82+
### Atomic Load
83+
84+
Atomic load operations ensure you read a complete, consistent value from shared memory, preventing torn reads:
85+
86+
```ruby
87+
# Set a value:
88+
buffer.set_value(:u32, 0, 42)
89+
90+
# Atomically read the value (ensures no torn reads):
91+
result = buffer.atomic_load(:u32, 0)
92+
# => 42
93+
```
94+
95+
Use `atomic_load` instead of `get_value` when reading values that may be modified by other threads or processes, as it provides memory ordering guarantees and prevents data races.
96+
97+
### Atomic Store
98+
99+
Atomic store operations ensure you write a complete value atomically to shared memory:
100+
101+
```ruby
102+
# Atomically write a value:
103+
buffer.atomic_store(:u32, 0, 42)
104+
105+
# Read it back:
106+
result = buffer.atomic_load(:u32, 0)
107+
# => 42
108+
```
109+
110+
Use `atomic_store` instead of `set_value` when writing values that may be read by other threads or processes, as it provides memory ordering guarantees and prevents torn writes.
111+
112+
**Note**: `atomic_load` and `atomic_store` work on raw bytes in host endian, matching the atomic operations themselves. Both `:u32` and `:U32` are equivalent for atomic operations.
113+
80114
### Compare and Swap
81115

82116
Compare-and-swap operations enable lock-free algorithms and optimistic concurrency:
@@ -88,7 +122,7 @@ buffer.set_value(:u32, 0, 10)
88122
# Atomically swap if current value matches expected:
89123
swapped = buffer.atomic_compare_and_swap(:u32, 0, 10, 20)
90124
# => true
91-
buffer.get_value(:u32, 0)
125+
buffer.atomic_load(:u32, 0)
92126
# => 20
93127

94128
# If value doesn't match, swap fails:
@@ -98,6 +132,8 @@ swapped = buffer.atomic_compare_and_swap(:u32, 0, 10, 30)
98132

99133
## Supported Operations
100134

135+
- `atomic_load(type, offset)` - Atomically read a value (prevents torn reads).
136+
- `atomic_store(type, offset, value)` - Atomically write a value (prevents torn writes).
101137
- `atomic_increment(type, offset, value = 1)` - Atomically increment a value.
102138
- `atomic_decrement(type, offset, value = 1)` - Atomically decrement a value.
103139
- `atomic_add(type, offset, value)` - Atomically add a value.
@@ -106,8 +142,3 @@ swapped = buffer.atomic_compare_and_swap(:u32, 0, 10, 30)
106142
- `atomic_or(type, offset, value)` - Atomically perform bitwise OR.
107143
- `atomic_xor(type, offset, value)` - Atomically perform bitwise XOR.
108144
- `atomic_compare_and_swap(type, offset, expected, desired)` - Atomically compare and swap.
109-
110-
## Requirements
111-
112-
- Ruby \>= 3.2.6.
113-
- `IO::Buffer` support (available in Ruby 3.2+).

lib/io/buffer/atomic/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class IO
99
class Buffer
1010
# @namespace
1111
module Atomic
12-
VERSION = "0.0.0"
12+
VERSION = "0.1.0"
1313
end
1414
end
1515
end

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Please see the [project documentation](https://socketry.github.io/io-buffer-atom
2020

2121
Please see the [project releases](https://socketry.github.io/io-buffer-atomic/releases/index) for all releases.
2222

23-
### Unreleased
23+
### v0.1.0
2424

2525
## Contributing
2626

releases.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Releases
22

3-
## Unreleased
3+
## v0.1.0

0 commit comments

Comments
 (0)