repo.or.cz
/
ruby.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
history
|
raw
|
HEAD
[rubygems/rubygems] Use a constant empty tar header to avoid extra allocations
[ruby.git]
/
benchmark
/
vm_thread_sized_queue3.rb
blob
ce5f1796d8ba15590473a5603259d883cec9c65d
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
11
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