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