Project

General

Profile

Bug #9302 ยป 0001-thread-fix-deadlock-freeze-on-SizedQueue-push.patch

normalperson (Eric Wong), 12/26/2013 07:07 PM

View differences:

ext/thread/thread.c
459 459
rb_szqueue_push(VALUE self, VALUE obj)
460 460
{
461 461
    struct waiting_delete args;
462
    args.waiting = GET_QUEUE_WAITERS(self);
462
    args.waiting = GET_SZQUEUE_WAITERS(self);
463 463
    args.th      = rb_thread_current();
464 464

  
465 465
    while (queue_length(self) >= GET_SZQUEUE_ULONGMAX(self)) {
test/thread/test_queue.rb
134 134
    assert_same q, retval
135 135
  end
136 136

  
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

  
137 160
  def test_queue_thread_raise
138 161
    q = Queue.new
139 162
    th1 = Thread.new do
140
-