ruby-changes:32504
From: charliesome <ko1@a...>
Date: Mon, 13 Jan 2014 12:18:42 +0900 (JST)
Subject: [ruby-changes:32504] charliesome:r44583 (trunk): * ext/thread/thread.c (rb_szqueue_push): check GET_SZQUEUE_WAITERS
charliesome 2014-01-13 12:18:38 +0900 (Mon, 13 Jan 2014) New Revision: 44583 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44583 Log: * ext/thread/thread.c (rb_szqueue_push): check GET_SZQUEUE_WAITERS instead of GET_QUEUE_WAITERS to prevent deadlock. Patch by Eric Wong. [Bug #9302] [ruby-core:59324] * test/thread/test_queue.rb: add test Modified files: trunk/ChangeLog trunk/ext/thread/thread.c trunk/test/thread/test_queue.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 44582) +++ ChangeLog (revision 44583) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Jan 13 12:03:00 2014 Charlie Somerville <charliesome@r...> + + * ext/thread/thread.c (rb_szqueue_push): check GET_SZQUEUE_WAITERS + instead of GET_QUEUE_WAITERS to prevent deadlock. Patch by Eric Wong. + [Bug #9302] [ruby-core:59324] + + * test/thread/test_queue.rb: add test + Sun Jan 12 16:41:10 2014 Nobuyoshi Nakada <nobu@r...> * iseq.c (iseq_load): keep type_map to get rid of memory leak. Index: ext/thread/thread.c =================================================================== --- ext/thread/thread.c (revision 44582) +++ ext/thread/thread.c (revision 44583) @@ -459,7 +459,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/thread/thread.c#L459 rb_szqueue_push(VALUE self, VALUE obj) { struct waiting_delete args; - args.waiting = GET_QUEUE_WAITERS(self); + args.waiting = GET_SZQUEUE_WAITERS(self); args.th = rb_thread_current(); while (queue_length(self) >= GET_SZQUEUE_ULONGMAX(self)) { Index: test/thread/test_queue.rb =================================================================== --- test/thread/test_queue.rb (revision 44582) +++ test/thread/test_queue.rb (revision 44583) @@ -134,6 +134,29 @@ class TestQueue < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/thread/test_queue.rb#L134 assert_same q, retval end + def test_sized_queue_throttle + q = SizedQueue.new(1) + i = 0 + consumer = Thread.new do + while q.pop + i += 1 + Thread.pass + end + end + nprod = 4 + npush = 100 + + producer = nprod.times.map do + Thread.new do + npush.times { q.push(true) } + end + end + producer.each(&:join) + q.push(nil) + consumer.join + assert_equal(nprod * npush, i) + end + def test_queue_thread_raise q = Queue.new th1 = Thread.new do -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/