The documentation clearly states what all_waitsany transferred block will execute after each thread execution; joindoesn't offer anything like that.
require "thwait"
threads = [Thread.new { 1 }, Thread.new { 2 }]
ThreadsWait.all_waits(threads) do |t|
puts "#{t} complete."
end
To do the same with join, I assume that you will need to do this:
threads.each do |t|
t.join
puts "#{t} complete."
end
, all_waits join_nowait, , join .
- , , join , ThreadsWait, . :
require "thwait"
require "benchmark"
loops = 100_000
Benchmark.bm do |x|
x.report do
loops.times do
threads = [Thread.new { 2 * 1000 }, Thread.new { 4 * 2000 }]
threads.each(&:join)
end
end
x.report do
loops.times do
threads = [Thread.new { 2 * 1000 }, Thread.new { 4 * 2000 }]
ThreadsWait.all_waits(threads)
end
end
end