Queue and SizedQueue: hidden gems in the Ruby standard library
Slides for a lightning talk showing how to implement thread pools using this two not-very-known classes in the Ruby standard library. RUG::B (Ruby Users Group Berlin) September 2014.
num_workers.times.map do Thread.new do until (item = queue.pop) == :END do_something(item) end end end list.each { |item| queue << item } num_workers.times { queue << :END } threads.each(&:join)
threads = num_workers.times.map do Thread.new do until (item = queue.pop) == :END do_something(item) end end end list.each { |item| queue << item } num_workers.times { queue << :END } threads.each(&:join)
threads = num_workers.times.map do Thread.new do until (item = queue.pop) == :END do_something(item) end end end list.each { |item| queue << item } num_workers.times { queue << :END } threads.each(&:join)
threads = num_workers.times.map do Thread.new do until (item = queue.pop) == :END do_something(item) end end end list.each { |item| queue << item } num_workers.times { queue << :END } threads.each(&:join) U GLY