ruby-changes:32820
From: nagachika <ko1@a...>
Date: Mon, 10 Feb 2014 01:07:53 +0900 (JST)
Subject: [ruby-changes:32820] nagachika:r44899 (ruby_2_0_0): merge revision(s) 44595: [Backport #9342]
nagachika 2014-02-10 01:07:41 +0900 (Mon, 10 Feb 2014) New Revision: 44899 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44899 Log: merge revision(s) 44595: [Backport #9342] * ext/thread/thread.c (rb_szqueue_clear): notify SZQUEUE_WAITERS on SizedQueue#clear. [ruby-core:59462] [Bug #9342] * test/thread/test_queue.rb: add test. the patch is from Justin Collins. Modified directories: branches/ruby_2_0_0/ Modified files: branches/ruby_2_0_0/ChangeLog branches/ruby_2_0_0/lib/thread.rb branches/ruby_2_0_0/test/thread/test_queue.rb branches/ruby_2_0_0/version.h Index: ruby_2_0_0/ChangeLog =================================================================== --- ruby_2_0_0/ChangeLog (revision 44898) +++ ruby_2_0_0/ChangeLog (revision 44899) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1 +Mon Feb 10 00:42:12 2014 Masaki Matsushita <glass.saga@g...> + + * ext/thread/thread.c (rb_szqueue_clear): notify SZQUEUE_WAITERS + on SizedQueue#clear. [ruby-core:59462] [Bug #9342] + + * test/thread/test_queue.rb: add test. the patch is from + Justin Collins. + Mon Feb 10 00:27:33 2014 Nobuyoshi Nakada <nobu@r...> * parse.y (local_push_gen, local_pop_gen): save cmdarg_stack to Index: ruby_2_0_0/lib/thread.rb =================================================================== --- ruby_2_0_0/lib/thread.rb (revision 44898) +++ ruby_2_0_0/lib/thread.rb (revision 44899) @@ -319,6 +319,18 @@ class SizedQueue < Queue https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/lib/thread.rb#L319 end # + # Removes all objects from the queue. + # + def clear + super + @mutex.synchronize do + @max.times do + @enque_cond.signal + end + end + end + + # # Alias of push # alias << push Index: ruby_2_0_0/version.h =================================================================== --- ruby_2_0_0/version.h (revision 44898) +++ ruby_2_0_0/version.h (revision 44899) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1 #define RUBY_VERSION "2.0.0" #define RUBY_RELEASE_DATE "2014-02-10" -#define RUBY_PATCHLEVEL 398 +#define RUBY_PATCHLEVEL 399 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 2 Index: ruby_2_0_0/test/thread/test_queue.rb =================================================================== --- ruby_2_0_0/test/thread/test_queue.rb (revision 44898) +++ ruby_2_0_0/test/thread/test_queue.rb (revision 44899) @@ -108,4 +108,71 @@ class TestQueue < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/thread/test_queue.rb#L108 end } end + + def test_sized_queue_clear + # Fill queue, then test that SizedQueue#clear wakes up all waiting threads + sq = SizedQueue.new(2) + 2.times { sq << 1 } + + t1 = Thread.new do + sq << 1 + end + + t2 = Thread.new do + sq << 1 + end + + t3 = Thread.new do + Thread.pass + sq.clear + end + + [t3, t2, t1].each(&:join) + assert_equal sq.length, 2 + 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 + begin + q.pop + rescue RuntimeError + sleep + end + end + th2 = Thread.new do + sleep 0.1 + q.pop + end + sleep 0.1 + th1.raise + sleep 0.1 + q << :s + assert_nothing_raised(TimeoutError) do + timeout(1) { th2.join } + end + end end Property changes on: ruby_2_0_0 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r44595 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/