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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e35d6cd7774994256c00cbf310fa5511aaafac0c55e4b0919102f22b444961d
4
- data.tar.gz: 763d472bdc50d97522f9a9f630f6d51f2db4832f9d507ca27d0f6dbae761ca54
3
+ metadata.gz: ecc5a5a825a6636db5718458318ba2650c05edb9a5a1198947f82e94596a974e
4
+ data.tar.gz: 7a08fbdf2e3362e03450ccb5d2342055c8e50832afae4bc709c5e1c5e187f88b
5
5
  SHA512:
6
- metadata.gz: a39511160e42082e08f9d435a29ffe658325d0e93fa10818a6f60b5f54882bf698ce2d2dcd655a6cbde19bea9cd7ebc2ede86fd8ff5e70e95bb94750400a7f36
7
- data.tar.gz: 89800c8d9fe359a497be8a71c463e3d22ef1585752d3320c85aeae0051634b41f70c78ace27502b452231b088de4a8e359ac7ab5be8ffa71836cdf564c9c2240
6
+ metadata.gz: f52cfbc19feaac870429dc893cbbf3541120e9beeaf20723d9f705b6a74835891473a299b682531d593e5adb1d2b3b75a0eed365b29e3490c1b921ea59aa4714
7
+ data.tar.gz: f797297e13eb693db8759e2bef195ed57288530dd05c8188b67dc1c9df1378476ed4e252b48385a2d951350e6e0f94f6b7aa3a2680d40885759d50fbdcdac1e9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.8.1] - 2025-11-01
4
+
5
+ - Don't require `AtomicThreadPool#<<` to be given a shareable proc
6
+
3
7
  ## [0.8.0] - 2025-11-01
4
8
 
5
9
  - Fix Ractor safety (requires Ruby 3.5+)
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 (including queueing them with `AtomicThreadPool#<<`), create them
104
- > using `Ractor.shareable_proc`, as `Ractor.make_shareable` cannot convert regular procs to
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 << shareable_proc { sleep(0.2) }
365
+ pool << proc { sleep(0.2) }
375
366
  end
376
367
 
377
368
  100.times do
378
- pool << shareable_proc { 1_000_000.times.map(&:itself).sum }
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.0
395
+ atomic-ruby version: 0.8.1
405
396
 
406
397
  Benchmark Results:
407
- Concurrent Ruby Thread Pool: 5.13772 seconds
408
- Atomic Ruby Atomic Thread Pool: 4.893086 seconds
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
- @state = Atom.new(queue: [], shutdown: false)
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
- if current_state[:shutdown]
30
- current_state
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
- @state.value[:queue].length
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 @state.value[:queue].empty?
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] && current_state[:queue].empty?
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 = current_state[:queue].first
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AtomicRuby
4
- VERSION = "0.8.0"
4
+ VERSION = "0.8.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atomic-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Young