summaryrefslogtreecommitdiff
path: root/thread_sync.c
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-25 18:09:02 (GMT)
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-25 18:09:02 (GMT)
commit3b60f4a590ad9c8144804cd4d26f260a33bc5818 (patch)
treef16310ef1b1168f7f6a65aa9f6e3ad2b96c296df /thread_sync.c
parentac1193d38f12e6ce5106f5413bcc57b6f585a2a1 (diff)
[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@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64058 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_sync.c')
-rw-r--r--thread_sync.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/thread_sync.c b/thread_sync.c
index 1624c47..279c644 100644
--- a/thread_sync.c
+++ b/thread_sync.c
@@ -737,6 +737,8 @@ queue_closed_result(VALUE self, struct rb_queue *q)
* end
* end
*
+ * consumer.join
+ *
*/
/*