atomic-ruby 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +7 -16
- data/lib/atomic-ruby/atomic_thread_pool.rb +9 -14
- data/lib/atomic-ruby/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ecc5a5a825a6636db5718458318ba2650c05edb9a5a1198947f82e94596a974e
|
|
4
|
+
data.tar.gz: 7a08fbdf2e3362e03450ccb5d2342055c8e50832afae4bc709c5e1c5e187f88b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f52cfbc19feaac870429dc893cbbf3541120e9beeaf20723d9f705b6a74835891473a299b682531d593e5adb1d2b3b75a0eed365b29e3490c1b921ea59aa4714
|
|
7
|
+
data.tar.gz: f797297e13eb693db8759e2bef195ed57288530dd05c8188b67dc1c9df1378476ed4e252b48385a2d951350e6e0f94f6b7aa3a2680d40885759d50fbdcdac1e9
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -100,9 +100,8 @@ p latch.count #=> 0
|
|
|
100
100
|
> [!NOTE]
|
|
101
101
|
> `Atom`, `AtomicBoolean`, and `AtomicCountDownLatch` are Ractor-safe in Ruby 3.5+.
|
|
102
102
|
>
|
|
103
|
-
> When storing procs in atoms
|
|
104
|
-
>
|
|
105
|
-
> shareable ones when the proc's context is not shareable.
|
|
103
|
+
> When storing procs in atoms, create them using `Ractor.shareable_proc`, as `Ractor.make_shareable`
|
|
104
|
+
> cannot convert regular procs to shareable ones when the proc's context is not shareable.
|
|
106
105
|
>
|
|
107
106
|
> ```ruby
|
|
108
107
|
> # This will raise an error in Ruby 3.5+ (proc created in non-shareable context)
|
|
@@ -353,14 +352,6 @@ require "benchmark"
|
|
|
353
352
|
require "concurrent-ruby"
|
|
354
353
|
require_relative "../lib/atomic-ruby"
|
|
355
354
|
|
|
356
|
-
def shareable_proc(&block)
|
|
357
|
-
if AtomicRuby::RACTOR_SAFE
|
|
358
|
-
Ractor.shareable_proc(&block)
|
|
359
|
-
else
|
|
360
|
-
block
|
|
361
|
-
end
|
|
362
|
-
end
|
|
363
|
-
|
|
364
355
|
results = []
|
|
365
356
|
|
|
366
357
|
2.times do |idx|
|
|
@@ -371,11 +362,11 @@ results = []
|
|
|
371
362
|
end
|
|
372
363
|
|
|
373
364
|
100.times do
|
|
374
|
-
pool <<
|
|
365
|
+
pool << proc { sleep(0.2) }
|
|
375
366
|
end
|
|
376
367
|
|
|
377
368
|
100.times do
|
|
378
|
-
pool <<
|
|
369
|
+
pool << proc { 1_000_000.times.map(&:itself).sum }
|
|
379
370
|
end
|
|
380
371
|
|
|
381
372
|
pool.shutdown
|
|
@@ -401,11 +392,11 @@ puts "Atomic Ruby Atomic Thread Pool: #{results[1].real.round(6)} seconds"
|
|
|
401
392
|
|
|
402
393
|
ruby version: ruby 3.5.0dev (2025-10-31T18:08:15Z master 980e18496e) +YJIT +PRISM [arm64-darwin25]
|
|
403
394
|
concurrent-ruby version: 1.3.5
|
|
404
|
-
atomic-ruby version: 0.8.
|
|
395
|
+
atomic-ruby version: 0.8.1
|
|
405
396
|
|
|
406
397
|
Benchmark Results:
|
|
407
|
-
Concurrent Ruby Thread Pool: 5.
|
|
408
|
-
Atomic Ruby Atomic Thread Pool: 4.
|
|
398
|
+
Concurrent Ruby Thread Pool: 5.139026 seconds
|
|
399
|
+
Atomic Ruby Atomic Thread Pool: 4.833597 seconds
|
|
409
400
|
```
|
|
410
401
|
|
|
411
402
|
</details>
|
|
@@ -17,7 +17,8 @@ module AtomicRuby
|
|
|
17
17
|
@size = size
|
|
18
18
|
@name = name
|
|
19
19
|
|
|
20
|
-
@
|
|
20
|
+
@queue = Queue.new
|
|
21
|
+
@state = Atom.new(shutdown: false)
|
|
21
22
|
@started_threads = Atom.new(0)
|
|
22
23
|
@threads = []
|
|
23
24
|
|
|
@@ -26,11 +27,8 @@ module AtomicRuby
|
|
|
26
27
|
|
|
27
28
|
def <<(work)
|
|
28
29
|
state = @state.swap do |current_state|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
else
|
|
32
|
-
current_state.merge(queue: [*current_state[:queue], work])
|
|
33
|
-
end
|
|
30
|
+
@queue.push(work) unless current_state[:shutdown]
|
|
31
|
+
current_state
|
|
34
32
|
end
|
|
35
33
|
raise EnqueuedWorkAfterShutdownError if state[:shutdown]
|
|
36
34
|
end
|
|
@@ -40,7 +38,7 @@ module AtomicRuby
|
|
|
40
38
|
end
|
|
41
39
|
|
|
42
40
|
def queue_length
|
|
43
|
-
@
|
|
41
|
+
@queue.size
|
|
44
42
|
end
|
|
45
43
|
|
|
46
44
|
def shutdown
|
|
@@ -55,7 +53,7 @@ module AtomicRuby
|
|
|
55
53
|
end
|
|
56
54
|
return if already_shutdown
|
|
57
55
|
|
|
58
|
-
Thread.pass until @
|
|
56
|
+
Thread.pass until @queue.empty?
|
|
59
57
|
|
|
60
58
|
@threads.each(&:join)
|
|
61
59
|
end
|
|
@@ -76,15 +74,12 @@ module AtomicRuby
|
|
|
76
74
|
should_shutdown = false
|
|
77
75
|
|
|
78
76
|
@state.swap do |current_state|
|
|
79
|
-
if current_state[:shutdown] &&
|
|
77
|
+
if current_state[:shutdown] && @queue.empty?
|
|
80
78
|
should_shutdown = true
|
|
81
|
-
current_state
|
|
82
|
-
elsif current_state[:queue].empty?
|
|
83
|
-
current_state
|
|
84
79
|
else
|
|
85
|
-
work =
|
|
86
|
-
current_state.merge(queue: current_state[:queue].drop(1))
|
|
80
|
+
work = @queue.pop(timeout: 0)
|
|
87
81
|
end
|
|
82
|
+
current_state
|
|
88
83
|
end
|
|
89
84
|
|
|
90
85
|
if should_shutdown
|
data/lib/atomic-ruby/version.rb
CHANGED