今天看啥
热点:

Ruby实现生产者和消费者代码分享,ruby生产者


#ruby实现生产者和消费者代码
 
require 'thread'
queue = Queue.new
consumers = Thread.new do
  5.times do |i|
    obj = queue.pop
    print "consumer :#{i}\n"
    sleep(rand(0.05))
  end
end
 
producters = Thread.new do
  5.times do |i|
    sleep(0.1)
    print "producter : #{i}\n"
    queue.push("Item #{i}")
  end
end
 
producters.join
consumers.join

www.bkjia.comtruehttp://www.bkjia.com/ruby/1004695.htmlTechArticleRuby实现生产者和消费者代码分享,ruby生产者 #ruby实现生产者和消费者代码 require 'thread'queue = Queue.newconsumers = Thread.new do 5.times do |i| obj = q...

相关文章

帮客评论

视觉看点