Skip to content

Commit 9a372fa

Browse files
committed
merge revision(s) 44583: [Backport ruby#9302]
* ext/thread/thread.c (rb_szqueue_push): check GET_SZQUEUE_WAITERS instead of GET_QUEUE_WAITERS to prevent deadlock. Patch by Eric Wong. [Bug ruby#9302] [ruby-core:59324] * test/thread/test_queue.rb: add test git-svn-id: svn+ssh://svn.ruby-lang.org/ruby/branches/ruby_2_1@44847 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 7d53e2b commit 9a372fa

4 files changed

Lines changed: 33 additions & 2 deletions

File tree

ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Wed Feb 5 23:57:05 2014 Charlie Somerville <charliesome@ruby-lang.org>
2+
3+
* ext/thread/thread.c (rb_szqueue_push): check GET_SZQUEUE_WAITERS
4+
instead of GET_QUEUE_WAITERS to prevent deadlock. Patch by Eric Wong.
5+
[Bug #9302] [ruby-core:59324]
6+
7+
* test/thread/test_queue.rb: add test
8+
19
Wed Feb 5 23:43:30 2014 NAKAMURA Usaku <usa@ruby-lang.org>
210

311
* hash.c (rb_objid_hash): should return `long'. brushup r44534.

ext/thread/thread.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ static VALUE
459459
rb_szqueue_push(VALUE self, VALUE obj)
460460
{
461461
struct waiting_delete args;
462-
args.waiting = GET_QUEUE_WAITERS(self);
462+
args.waiting = GET_SZQUEUE_WAITERS(self);
463463
args.th = rb_thread_current();
464464

465465
while (queue_length(self) >= GET_SZQUEUE_ULONGMAX(self)) {

test/thread/test_queue.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,29 @@ def test_sized_queue_clear_return_value
134134
assert_same q, retval
135135
end
136136

137+
def test_sized_queue_throttle
138+
q = SizedQueue.new(1)
139+
i = 0
140+
consumer = Thread.new do
141+
while q.pop
142+
i += 1
143+
Thread.pass
144+
end
145+
end
146+
nprod = 4
147+
npush = 100
148+
149+
producer = nprod.times.map do
150+
Thread.new do
151+
npush.times { q.push(true) }
152+
end
153+
end
154+
producer.each(&:join)
155+
q.push(nil)
156+
consumer.join
157+
assert_equal(nprod * npush, i)
158+
end
159+
137160
def test_queue_thread_raise
138161
q = Queue.new
139162
th1 = Thread.new do

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define RUBY_VERSION "2.1.1"
22
#define RUBY_RELEASE_DATE "2014-02-05"
3-
#define RUBY_PATCHLEVEL 22
3+
#define RUBY_PATCHLEVEL 23
44

55
#define RUBY_RELEASE_YEAR 2014
66
#define RUBY_RELEASE_MONTH 2

0 commit comments

Comments
 (0)