1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

ext/thread: SizedQueue#max= wakes up waiters properly

* ext/thread/thread.c (rb_szqueue_max_set): use correct queue and
	  limit wakeups.  [Bug #9343][ruby-core:60517]
	* test/thread/test_queue.rb (test_sized_queue_assign_max):
	  test for bug

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44852 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
normal 2014-02-05 23:35:06 +00:00
parent b9a4cf2aca
commit 2d603f9fee
3 changed files with 15 additions and 1 deletions

View file

@ -1,3 +1,10 @@
Thu Feb 6 08:23:28 2014 Eric Wong <e@80x24.org>
* ext/thread/thread.c (rb_szqueue_max_set): use correct queue and
limit wakeups. [Bug #9343][ruby-core:60517]
* test/thread/test_queue.rb (test_sized_queue_assign_max):
test for bug
Thu Feb 6 07:18:01 2014 Eric Hodel <drbrain@segment7.net>
* lib/rubygems: Update to RubyGems 2.2.2. Complete history at:

View file

@ -437,7 +437,7 @@ rb_szqueue_max_set(VALUE self, VALUE vmax)
diff = max - GET_SZQUEUE_ULONGMAX(self);
}
RSTRUCT_SET(self, SZQUEUE_MAX, vmax);
while (diff > 0 && !NIL_P(t = rb_ary_shift(GET_QUEUE_QUE(self)))) {
while (diff-- > 0 && !NIL_P(t = rb_ary_shift(GET_SZQUEUE_WAITERS(self)))) {
rb_thread_wakeup_alive(t);
}
return vmax;

View file

@ -55,6 +55,13 @@ class TestQueue < Test::Unit::TestCase
assert_equal(1, q.max)
assert_raise(ArgumentError) { q.max = -1 }
assert_equal(1, q.max)
before = q.max
q.max.times { q << 1 }
t1 = Thread.new { q << 1 }
sleep 0.01 until t1.stop?
q.max = q.max + 1
assert_equal before + 1, q.max
end
def test_queue_pop_interrupt