lib/threads.rb in threads-0.1.0 vs lib/threads.rb in threads-0.2.0

- old
+ new

@@ -31,27 +31,30 @@ class Threads def initialize(total = Concurrent.processor_count * 8) @total = total end - def assert(reps = 0) + def assert(reps = @total) + if reps < @total + raise "Repetition counter #{reps} can't be smaller than #{@total}" + end done = Concurrent::AtomicFixnum.new - cycles = Concurrent::AtomicFixnum.new + rep = Concurrent::AtomicFixnum.new pool = Concurrent::FixedThreadPool.new(@total) latch = Concurrent::CountDownLatch.new(1) @total.times do |t| pool.post do Thread.current.name = "assert-thread-#{t}" latch.wait(10) loop do + r = rep.increment + break if r > reps begin - yield t + yield(t, r - 1) rescue StandardError => e puts Backtrace.new(e) raise e end - cycles.increment - break if cycles.value > reps end done.increment end end latch.count_down