2013-11-06 00:21:05 +00:00
|
|
|
require 'thread'
|
|
|
|
|
|
|
|
n = 1_000_000
|
2016-08-30 06:22:30 +00:00
|
|
|
q = Thread::Queue.new
|
2013-11-06 00:21:05 +00:00
|
|
|
consumer = Thread.new{
|
|
|
|
while q.pop
|
|
|
|
# consuming
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
producer = Thread.new{
|
|
|
|
n.times{
|
|
|
|
q.push true
|
|
|
|
}
|
|
|
|
q.push nil
|
|
|
|
}
|
|
|
|
|
|
|
|
consumer.join
|