[前][次][番号順一覧][スレッド一覧]

ruby-changes:51844

From: tenderlove <ko1@a...>
Date: Thu, 26 Jul 2018 03:09:07 +0900 (JST)
Subject: [ruby-changes:51844] tenderlove:r64058 (trunk): [Doc] Recover example about Queue

tenderlove	2018-07-26 03:09:02 +0900 (Thu, 26 Jul 2018)

  New Revision: 64058

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64058

  Log:
    [Doc] Recover example about Queue
    
    `trunk@42862` dropped example's last line.
    
    https://github.com/ruby/ruby/commit/e334bb2ce5d8876b020ab681f21595e2e1c9d601#diff-8783a9b452e430bcf0d7b0c6e34f1db0L144
    https://github.com/ruby/ruby/commit/e334bb2ce5d8876b020ab681f21595e2e1c9d601#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@g...>

  Modified files:
    trunk/thread_sync.c
Index: thread_sync.c
===================================================================
--- thread_sync.c	(revision 64057)
+++ thread_sync.c	(revision 64058)
@@ -737,6 +737,8 @@ queue_closed_result(VALUE self, struct r https://github.com/ruby/ruby/blob/trunk/thread_sync.c#L737
  *	  end
  *	end
  *
+ *	consumer.join
+ *
  */
 
 /*

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]