Project

General

Profile

Bug #9342

[PATCH] SizedQueue#clear does not notify waiting threads in Ruby 1.9.3

Added by jsc (Justin Collins) over 4 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Target version:
ruby -v:
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-darwin11.4.2]
[ruby-core:59462]

Description

In Ruby 1.9.3, when SizedQueue#clear is called, it empties the queue but does not notify waiting threads that the queue is empty. This typically leads to deadlock when the queue is full.

For example:

sq = SizedQueue.new(1)
sq << 1 # Fill queue

t1 = Thread.new do
sq << 1 # Attempt to add another item to queue, fail and go to sleep waiting
end

t2 = Thread.new do
Thread.pass
sq.clear
end

t2.join # Empty queue
t1.join # Deadlock, t1 continues to sleep

Associated revisions

Revision 79e69ec7
Added by glass over 4 years ago

  • ext/thread/thread.c (rb_szqueue_clear): notify SZQUEUE_WAITERS
    on SizedQueue#clear. [Bug #9342]

  • test/thread/test_queue.rb: add test. the patch is from
    Justin Collins.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 44595
Added by glass over 4 years ago

  • ext/thread/thread.c (rb_szqueue_clear): notify SZQUEUE_WAITERS
    on SizedQueue#clear. [Bug #9342]

  • test/thread/test_queue.rb: add test. the patch is from
    Justin Collins.

Revision 44595
Added by Glass_saga (Masaki Matsushita) over 4 years ago

  • ext/thread/thread.c (rb_szqueue_clear): notify SZQUEUE_WAITERS
    on SizedQueue#clear. [Bug #9342]

  • test/thread/test_queue.rb: add test. the patch is from
    Justin Collins.

Revision 44595
Added by glass over 4 years ago

  • ext/thread/thread.c (rb_szqueue_clear): notify SZQUEUE_WAITERS
    on SizedQueue#clear. [Bug #9342]

  • test/thread/test_queue.rb: add test. the patch is from
    Justin Collins.

Revision 44595
Added by glass over 4 years ago

  • ext/thread/thread.c (rb_szqueue_clear): notify SZQUEUE_WAITERS
    on SizedQueue#clear. [Bug #9342]

  • test/thread/test_queue.rb: add test. the patch is from
    Justin Collins.

Revision 44595
Added by glass over 4 years ago

  • ext/thread/thread.c (rb_szqueue_clear): notify SZQUEUE_WAITERS
    on SizedQueue#clear. [Bug #9342]

  • test/thread/test_queue.rb: add test. the patch is from
    Justin Collins.

Revision 08e1428b
Added by nagachika (Tomoyuki Chikanaga) over 4 years ago

merge revision(s) 44595: [Backport #9342]

* ext/thread/thread.c (rb_szqueue_clear): notify SZQUEUE_WAITERS
  on SizedQueue#clear.  [Bug #9342]

* test/thread/test_queue.rb: add test. the patch is from
  Justin Collins.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@44899 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision d88502b7
Added by usa (Usaku NAKAMURA) over 4 years ago

  • lib/thread.rb (SizedQueue#clear): wake waiting threads when called.
    [Bug #9342]

  • test/thread/test_queue.rb: add a test for above.

patched by Justin Collins.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@44932 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision a98f024d
Added by naruse (Yui NARUSE) over 4 years ago

merge revision(s) 44595: [Backport #9342]

* ext/thread/thread.c (rb_szqueue_clear): notify SZQUEUE_WAITERS
  on SizedQueue#clear.  [Bug #9342]

* test/thread/test_queue.rb: add test. the patch is from
  Justin Collins.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@45104 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

History

#1 [ruby-core:59464] Updated by jsc (Justin Collins) over 4 years ago

Looks like this is also a problem in 2.0.0, although the implementation is a little different. Attaching patch for 2.0.0 too although it's probably clear.

#2 [ruby-core:59465] Updated by normalperson (Eric Wong) over 4 years ago

I agree this is a problem. This also affects 2.1.0 and trunk (where
SizedQueue is C).

#3 [ruby-core:59572] Updated by ko1 (Koichi Sasada) over 4 years ago

  • Category set to ext
  • Assignee set to ko1 (Koichi Sasada)
  • Target version set to 2.2.0

#4 Updated by Anonymous over 4 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

Applied in changeset r44595.


  • ext/thread/thread.c (rb_szqueue_clear): notify SZQUEUE_WAITERS
    on SizedQueue#clear. [Bug #9342]

  • test/thread/test_queue.rb: add test. the patch is from
    Justin Collins.

#5 [ruby-core:59835] Updated by jsc (Justin Collins) over 4 years ago

Thank you!

As far as I can tell, SizedQueue#clear has never notified waiting threads since it was introduced in Ruby 1.4. Perhaps something with green threads allowed it to work anyway? It is definitely an issue in 1.9.3 and later.

#6 [ruby-core:60474] Updated by usa (Usaku NAKAMURA) over 4 years ago

  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN to 1.9.3: REQUIRED, 2.0.0: REQUIRED, 2.1: REQUIRED

#7 [ruby-core:60626] Updated by nagachika (Tomoyuki Chikanaga) over 4 years ago

  • Backport changed from 1.9.3: REQUIRED, 2.0.0: REQUIRED, 2.1: REQUIRED to 1.9.3: REQUIRED, 2.0.0: DONE, 2.1: REQUIRED

1.9.3 and 2.0.0 has different implementation of Queue/SizedQueue from 2.1/trunk.
I partially backported r44595 for test, and commited a patch for ruby_2_0_0 at r44899.

#8 [ruby-core:60691] Updated by usa (Usaku NAKAMURA) over 4 years ago

  • Backport changed from 1.9.3: REQUIRED, 2.0.0: DONE, 2.1: REQUIRED to 1.9.3: DONE, 2.0.0: DONE, 2.1: REQUIRED

Commited to ruby_1_9_3 at r44932.
Thank you, Justin!

#9 [ruby-core:60966] Updated by naruse (Yui NARUSE) over 4 years ago

  • Backport changed from 1.9.3: DONE, 2.0.0: DONE, 2.1: REQUIRED to 1.9.3: DONE, 2.0.0: DONE, 2.1: DONE

r45104.

Also available in: Atom PDF