atomic-ruby 0.3.1 → 0.3.2

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: fc55b63bd9de85a395232f89184e97aa80e08e8e082981f2b17012fd1b56b5c0
4
- data.tar.gz: 25cffc0cbb45f1d145d3b99380decc91a39ef82415833781bed40ba2583286a8
3
+ metadata.gz: 7e47f4b67bd3d4dcaecbd560ed61b8dc4c86c24882b52279a5d0e92fd6de666a
4
+ data.tar.gz: 2fb299af89ccc871b7c8b3d6ef18f15924e98b90ad196143c0ea9fa3cac76419
5
5
  SHA512:
6
- metadata.gz: 1420ff50010eec4386301619d4866c1e96aec8f91936e464b2ed56276607fd6dfaf88d0cc5582ee255c06a15928a2b1390f1a2e18ceb443ee0d74fa190a36ee9
7
- data.tar.gz: 80ceb6dd2348ea38bbd8b63223fc7ab27a6d36026d0e028fc0aef60dd9f92885b29adb5fa997b551b54c9aadbaca24fdd71a4f7b1d94337f3a3887955c108a5b
6
+ metadata.gz: fb201628eedea540bea2a8436daf0bb9f9db3cf2f0cd1caa5d27a54af840b992474cf4e08496a52c16f963ab311cd14f3796977f6777140c648e38cd283a6679
7
+ data.tar.gz: fe346ae21ffa67e8ed82048a1b79fe2eada3f101e2b812112eef689139f924e01b420b6e0d56f37ca2c795e597bd86631e79f8d93fa5d32f50a77ef7eb1f9734
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.2] - 2025-06-14
4
+
5
+ - Fix `AtomicThreadPool#<<` shutdown check race condition
6
+
3
7
  ## [0.3.1] - 2025-06-08
4
8
 
5
9
  - Fix current queue being mutated in `AtomicThreadPool#<<`
data/README.md CHANGED
@@ -169,6 +169,7 @@ results = []
169
169
  results << result
170
170
  end
171
171
 
172
+ puts "\n"
172
173
  puts "ruby version: #{RUBY_DESCRIPTION}"
173
174
  puts "concurrent-ruby version: #{Concurrent::VERSION}"
174
175
  puts "atomic-ruby version: #{AtomicRuby::VERSION}"
@@ -189,7 +190,7 @@ puts "Atomic Ruby Atomic Bank Account: #{results[2].real.round(6)} seconds"
189
190
 
190
191
  ruby version: ruby 3.4.4 (2025-05-14 revision a38531fd3f) +YJIT +PRISM [arm64-darwin24]
191
192
  concurrent-ruby version: 1.3.5
192
- atomic-ruby version: 0.3.0
193
+ atomic-ruby version: 0.3.2
193
194
 
194
195
  Balances:
195
196
  Synchronized Bank Account Balance: 975
@@ -197,9 +198,9 @@ Concurrent Ruby Atomic Bank Account Balance: 975
197
198
  Atomic Ruby Atomic Bank Account Balance: 975
198
199
 
199
200
  Benchmark Results:
200
- Synchronized Bank Account: 5.125638 seconds
201
- Concurrent Ruby Atomic Bank Account: 5.114936 seconds
202
- Atomic Ruby Atomic Bank Account: 5.108171 seconds
201
+ Synchronized Bank Account: 5.130792 seconds
202
+ Concurrent Ruby Atomic Bank Account: 5.121400 seconds
203
+ Atomic Ruby Atomic Bank Account: 5.119191 seconds
203
204
  ```
204
205
 
205
206
  </details>
@@ -215,6 +216,23 @@ require "benchmark/ips"
215
216
  require "concurrent-ruby"
216
217
  require_relative "../lib/atomic-ruby"
217
218
 
219
+ module Benchmark
220
+ module IPS
221
+ class Job
222
+ class StreamReport
223
+ def start_warming
224
+ @out.puts "\n"
225
+ @out.puts "ruby version: #{RUBY_DESCRIPTION}"
226
+ @out.puts "concurrent-ruby version: #{Concurrent::VERSION}"
227
+ @out.puts "atomic-ruby version: #{AtomicRuby::VERSION}"
228
+ @out.puts "\n"
229
+ @out.puts "Warming up --------------------------------------"
230
+ end
231
+ end
232
+ end
233
+ end
234
+ end
235
+
218
236
  Benchmark.ips do |x|
219
237
  x.report("Synchronized Boolean Toggle") do
220
238
  boolean = false
@@ -261,26 +279,29 @@ end
261
279
  ```
262
280
  > bundle exec rake compile && bundle exec ruby examples/atomic_boolean_benchmark.rb
263
281
 
264
- ruby 3.4.4 (2025-05-14 revision a38531fd3f) +YJIT +PRISM [arm64-darwin24]
282
+ ruby version: ruby 3.4.4 (2025-05-14 revision a38531fd3f) +YJIT +PRISM [arm64-darwin24]
283
+ concurrent-ruby version: 1.3.5
284
+ atomic-ruby version: 0.3.2
285
+
265
286
  Warming up --------------------------------------
266
287
  Synchronized Boolean Toggle
267
- 83.000 i/100ms
288
+ 87.000 i/100ms
268
289
  Concurrent Ruby Atomic Boolean Toggle
269
- 58.000 i/100ms
290
+ 81.000 i/100ms
270
291
  Atomic Ruby Atomic Boolean Toggle
271
- 88.000 i/100ms
292
+ 92.000 i/100ms
272
293
  Calculating -------------------------------------
273
294
  Synchronized Boolean Toggle
274
- 775.5526.2%) i/s (1.29 ms/i) - 3.901k in 5.051649s
295
+ 969.2055.8%) i/s (1.03 ms/i) - 4.872k in 5.043520s
275
296
  Concurrent Ruby Atomic Boolean Toggle
276
- 741.6553.5%) i/s (1.35 ms/i) - 3.712k in 5.011183s
297
+ 885.5465.2%) i/s (1.13 ms/i) - 4.455k in 5.044282s
277
298
  Atomic Ruby Atomic Boolean Toggle
278
- 881.9162.8%) i/s (1.13 ms/i) - 4.488k in 5.092910s
299
+ 1.154k5.3%) i/s (866.65 μs/i) - 5.796k in 5.037272s
279
300
 
280
301
  Comparison:
281
- Atomic Ruby Atomic Boolean Toggle: 881.9 i/s
282
- Synchronized Boolean Toggle: 775.6 i/s - 1.14x slower
283
- Concurrent Ruby Atomic Boolean Toggle: 741.7 i/s - 1.19x slower
302
+ Atomic Ruby Atomic Boolean Toggle: 1153.9 i/s
303
+ Synchronized Boolean Toggle: 969.2 i/s - 1.19x slower
304
+ Concurrent Ruby Atomic Boolean Toggle: 885.5 i/s - 1.30x slower
284
305
  ```
285
306
 
286
307
  </details>
@@ -315,17 +336,15 @@ results = []
315
336
  pool << -> { 1_000_000.times.map(&:itself).sum }
316
337
  end
317
338
 
318
- # concurrent-ruby does not wait for threads to die on shutdown
319
- threads = if idx == 0
320
- pool.instance_variable_get(:@pool).map { |worker| worker.instance_variable_get(:@thread) }
321
- end
322
339
  pool.shutdown
323
- threads&.each(&:join)
340
+ # concurrent-ruby's #shutdown does not wait for threads to terminate
341
+ pool.wait_for_termination if idx == 0
324
342
  end
325
343
 
326
344
  results << result
327
345
  end
328
346
 
347
+ puts "\n"
329
348
  puts "ruby version: #{RUBY_DESCRIPTION}"
330
349
  puts "concurrent-ruby version: #{Concurrent::VERSION}"
331
350
  puts "atomic-ruby version: #{AtomicRuby::VERSION}"
@@ -340,11 +359,11 @@ puts "Atomic Ruby Atomic Thread Pool: #{results[1].real.round(6)} seconds"
340
359
 
341
360
  ruby version: ruby 3.4.4 (2025-05-14 revision a38531fd3f) +YJIT +PRISM [arm64-darwin24]
342
361
  concurrent-ruby version: 1.3.5
343
- atomic-ruby version: 0.3.0
362
+ atomic-ruby version: 0.3.2
344
363
 
345
364
  Benchmark Results:
346
- Concurrent Ruby Thread Pool: 5.136456 seconds
347
- Atomic Ruby Atomic Thread Pool: 4.700981 seconds
365
+ Concurrent Ruby Thread Pool: 5.032940 seconds
366
+ Atomic Ruby Atomic Thread Pool: 4.508259 seconds
348
367
  ```
349
368
 
350
369
  </details>
Binary file
@@ -23,11 +23,13 @@ module AtomicRuby
23
23
  raise UnsupportedWorkTypeError, "expected work to be a `Proc`, got #{work.class}"
24
24
  end
25
25
 
26
- if @stopping.true?
27
- raise InvalidWorkQueueingError, "cannot queue work during or after pool shutdown"
28
- end
26
+ @queue.swap do |current_queue|
27
+ if @stopping.true?
28
+ raise InvalidWorkQueueingError, "cannot queue work during or after pool shutdown"
29
+ end
29
30
 
30
- @queue.swap { |current_queue| current_queue += [work] }
31
+ current_queue += [work]
32
+ end
31
33
  true
32
34
  end
33
35
 
@@ -80,7 +82,7 @@ module AtomicRuby
80
82
  end
81
83
  end
82
84
 
83
- sleep(0.001) until @started_threads.value == @size
85
+ Thread.pass until @started_threads.value == @size
84
86
  end
85
87
  end
86
88
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AtomicRuby
4
- VERSION = "0.3.1"
4
+ VERSION = "0.3.2"
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.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Young
@@ -50,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
50
  - !ruby/object:Gem::Version
51
51
  version: '0'
52
52
  requirements: []
53
- rubygems_version: 3.6.7
53
+ rubygems_version: 3.7.0.dev
54
54
  specification_version: 4
55
55
  summary: Atomic primitives for Ruby
56
56
  test_files: []