#ruby实现生产者和消费者代码 require 'thread'queue = Queue.newconsumers = Thread.new do 5.times do |i| obj = queue.pop print "consumer :#{i}/n" sleep(rand(0.05)) endend producters = Thread.new do 5.times do |i| sleep(0.1) print "producter : #{i}/n" queue.push("Item #{i}") endend producters.joinconsumers.join
新闻热点
疑难解答