[rubygems/rubygems] Use a constant empty tar header to avoid extra allocations
[ruby.git] / benchmark / vm_thread_sized_queue3.rb
blobce5f1796d8ba15590473a5603259d883cec9c65d
1 require 'thread'
2 # many producers, one consumer
3 n = 1_000_000
4 m = 10
5 q = Thread::SizedQueue.new(100)
6 consumer = Thread.new do
7   while q.pop
8     # consuming
9   end
10 end
12 producers = m.times.map do
13   Thread.new do
14     while n > 0
15       q.push true
16       n -= 1
17     end
18   end
19 end
20 producers.each(&:join)
21 q.push nil
22 consumer.join