зеркало из https://github.com/github/ruby.git
[Doc] Recover example about Queue
`trunk@42862` dropped example's last line.e334bb2ce5 (diff-8783a9b452e430bcf0d7b0c6e34f1db0L144)
e334bb2ce5 (diff-38e7b9d781319cfbc49445f8f6625b8aR195)
This brings no output. ```queue_example1.rb queue = Queue.new producer = Thread.new do 5.times do |i| sleep rand(i) # simulate expense queue << i puts "#{i} produced" end end consumer = Thread.new do 5.times do |i| value = queue.pop sleep rand(i/2) # simulate expense puts "consumed #{value}" end end ``` ```queue_example2.rb queue = Queue.new producer = Thread.new do 5.times do |i| sleep rand(i) # simulate expense queue << i puts "#{i} produced" end end consumer = Thread.new do 5.times do |i| value = queue.pop sleep rand(i/2) # simulate expense puts "consumed #{value}" end end consumer.join ``` $ ruby queue_example1.rb $ $ ruby queue_example2.rb 0 produced 1 produced consumed 0 consumed 1 2 produced consumed 2 3 produced consumed 3 4 produced consumed 4 $ Co-Authored-By: Sanemat <o.gata.ken@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64058 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
ac1193d38f
Коммит
3b60f4a590
|
@ -737,6 +737,8 @@ queue_closed_result(VALUE self, struct rb_queue *q)
|
|||
* end
|
||||
* end
|
||||
*
|
||||
* consumer.join
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
|
|
Загрузка…
Ссылка в новой задаче