Project

General

Profile

Bug #12405

Queue doesn't work inside of trap

Added by kirillrdy (Kirill Radzikhovskyy) about 3 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
[ruby-core:75636]

Description

when adding things to the queue inside that trap blocking pop never unblocks

q = Queue.new
Signal.trap 'INT' do
  puts "got INT"
  q << 'something'
end

Thread.new {
  loop {
    sleep 1
    Process.kill :INT, $$
  }
}

q.pop

I know that there are limitations of what can be done inside of trap.
Looking at this https://bugs.ruby-lang.org/issues/6128 it looks like I should be able to use Queue inside a trap, but code above runs forever.
Also in jruby it behaives as expected ( at least in my understanding )

Associated revisions

Revision 57477
Added by ko1 (Koichi Sasada) over 2 years ago

use TRUE/FALSE.

Revision 57478
Added by ko1 (Koichi Sasada) over 2 years ago

define rb_thread_sleep_deadly_allow_spurious_wakeup().

  • thread.c, thread_sync.c: define new function rb_thread_sleep_deadly_allow_spurious_wakeup() and use it instead of using sleep_forever() directly.

Revision bfdfc99c
Added by ko1 (Koichi Sasada) over 2 years ago

allow Queue operation in trap.

  • thread_sync.c: allow spurious wakeup to check Queue status just after trap.
    [Bug #12405]

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

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

Revision 57479
Added by ko1 (Koichi Sasada) over 2 years ago

allow Queue operation in trap.

  • thread_sync.c: allow spurious wakeup to check Queue status just after trap.
    [Bug #12405]

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

Revision 57479
Added by ko1 (Koichi Sasada) over 2 years ago

allow Queue operation in trap.

  • thread_sync.c: allow spurious wakeup to check Queue status just after trap.
    [Bug #12405]

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

Revision 57479
Added by ko1 (Koichi Sasada) over 2 years ago

allow Queue operation in trap.

  • thread_sync.c: allow spurious wakeup to check Queue status just after trap.
    [Bug #12405]

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

Revision 57492
Added by nobu (Nobuyoshi Nakada) over 2 years ago

test_queue.rb: fix portability

  • test/thread/test_queue.rb (test_queue_with_trap): fix portability. use SIGINT instead of SIGUSR2 which is supported on not all platforms.

Revision 0c72a8f0
Added by naruse (Yui NARUSE) about 2 years ago

merge revision(s) 57477,57478,57479: [Backport #12405]

    use TRUE/FALSE.

    define rb_thread_sleep_deadly_allow_spurious_wakeup().

    * thread.c, thread_sync.c: define new function
      rb_thread_sleep_deadly_allow_spurious_wakeup() and use it instead of
      using sleep_forever() directly.

    allow Queue operation in trap.

    * thread_sync.c: allow spurious wakeup to check Queue status just after trap.
      [Bug #12405]

    * test/thread/test_queue.rb: add a test for it.

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

Revision 57879
Added by naruse (Yui NARUSE) about 2 years ago

merge revision(s) 57477,57478,57479: [Backport #12405]

use TRUE/FALSE.

define rb_thread_sleep_deadly_allow_spurious_wakeup().

* thread.c, thread_sync.c: define new function
  rb_thread_sleep_deadly_allow_spurious_wakeup() and use it instead of
  using sleep_forever() directly.

allow Queue operation in trap.

* thread_sync.c: allow spurious wakeup to check Queue status just after trap.
  [Bug #12405]

* test/thread/test_queue.rb: add a test for it.

Revision e120cc91
Added by nagachika (Tomoyuki Chikanaga) about 2 years ago

merge revision(s) 57477,57478,57479: [Backport #12405]

    use TRUE/FALSE.

    define rb_thread_sleep_deadly_allow_spurious_wakeup().

    * thread.c, thread_sync.c: define new function
      rb_thread_sleep_deadly_allow_spurious_wakeup() and use it instead of
      using sleep_forever() directly.

    allow Queue operation in trap.

    * thread_sync.c: allow spurious wakeup to check Queue status just after trap.
      [Bug #12405]

    * test/thread/test_queue.rb: add a test for it.

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

Revision 58036
Added by nagachika (Tomoyuki Chikanaga) about 2 years ago

merge revision(s) 57477,57478,57479: [Backport #12405]

use TRUE/FALSE.

define rb_thread_sleep_deadly_allow_spurious_wakeup().

* thread.c, thread_sync.c: define new function
  rb_thread_sleep_deadly_allow_spurious_wakeup() and use it instead of
  using sleep_forever() directly.

allow Queue operation in trap.

* thread_sync.c: allow spurious wakeup to check Queue status just after trap.
  [Bug #12405]

* test/thread/test_queue.rb: add a test for it.

Revision d014f463
Added by usa (Usaku NAKAMURA) about 2 years ago

merge revision(s) 57477,57478,57479,57492: [Backport #12405]

    use TRUE/FALSE.

    define rb_thread_sleep_deadly_allow_spurious_wakeup().

    * thread.c, thread_sync.c: define new function
      rb_thread_sleep_deadly_allow_spurious_wakeup() and use it instead of
      using sleep_forever() directly.

    allow Queue operation in trap.

    * thread_sync.c: allow spurious wakeup to check Queue status just after trap.
      [Bug #12405]

    * test/thread/test_queue.rb: add a test for it.

    test_queue.rb: fix portability

    * test/thread/test_queue.rb (test_queue_with_trap): fix
      portability.  use SIGINT instead of SIGUSR2 which is supported
      on not all platforms.

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

Revision 58115
Added by usa (Usaku NAKAMURA) about 2 years ago

merge revision(s) 57477,57478,57479,57492: [Backport #12405]

use TRUE/FALSE.

define rb_thread_sleep_deadly_allow_spurious_wakeup().

* thread.c, thread_sync.c: define new function
  rb_thread_sleep_deadly_allow_spurious_wakeup() and use it instead of
  using sleep_forever() directly.

allow Queue operation in trap.

* thread_sync.c: allow spurious wakeup to check Queue status just after trap.
  [Bug #12405]

* test/thread/test_queue.rb: add a test for it.

test_queue.rb: fix portability

* test/thread/test_queue.rb (test_queue_with_trap): fix
  portability.  use SIGINT instead of SIGUSR2 which is supported
  on not all platforms.

Revision 715f997a
Added by nagachika (Tomoyuki Chikanaga) about 2 years ago

merge revision(s) 57492: [Backport #12405]

    test_queue.rb: fix portability

    * test/thread/test_queue.rb (test_queue_with_trap): fix
      portability.  use SIGINT instead of SIGUSR2 which is supported
      on not all platforms.

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

Revision 58164
Added by nagachika (Tomoyuki Chikanaga) about 2 years ago

merge revision(s) 57492: [Backport #12405]

test_queue.rb: fix portability

* test/thread/test_queue.rb (test_queue_with_trap): fix
  portability.  use SIGINT instead of SIGUSR2 which is supported
  on not all platforms.

History

Updated by ko1 (Koichi Sasada) almost 3 years ago

  • Assignee set to ko1 (Koichi Sasada)
  • Description updated (diff)
#2

Updated by ko1 (Koichi Sasada) over 2 years ago

  • Status changed from Open to Closed

Applied in changeset r57479.


allow Queue operation in trap.

  • thread_sync.c: allow spurious wakeup to check Queue status just after trap.
    [Bug #12405]

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

Updated by ko1 (Koichi Sasada) over 2 years ago

We need to check Queue status change after trap handler.

Sorry for my late response and thank you for your reporting it.

Updated by naruse (Yui NARUSE) about 2 years ago

  • Backport changed from 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN to 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: DONE

ruby_2_4 r57879 merged revision(s) 57477,57478,57479.

Updated by nagachika (Tomoyuki Chikanaga) about 2 years ago

  • Backport changed from 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: DONE to 2.1: UNKNOWN, 2.2: REQUIRED, 2.3: REQUIRED, 2.4: DONE

Updated by nagachika (Tomoyuki Chikanaga) about 2 years ago

  • Backport changed from 2.1: UNKNOWN, 2.2: REQUIRED, 2.3: REQUIRED, 2.4: DONE to 2.1: UNKNOWN, 2.2: REQUIRED, 2.3: DONE, 2.4: DONE

ruby_2_3 r58036 merged revision(s) 57477,57478,57479.

Updated by usa (Usaku NAKAMURA) about 2 years ago

  • Backport changed from 2.1: UNKNOWN, 2.2: REQUIRED, 2.3: DONE, 2.4: DONE to 2.1: UNKNOWN, 2.2: REQUIRED, 2.3: REQUIRED, 2.4: DONE

nagachika-san, r57492 is also required.

Updated by usa (Usaku NAKAMURA) about 2 years ago

  • Backport changed from 2.1: UNKNOWN, 2.2: REQUIRED, 2.3: REQUIRED, 2.4: DONE to 2.1: UNKNOWN, 2.2: DONE, 2.3: REQUIRED, 2.4: DONE

ruby_2_2 r58115 merged revision(s) 57477,57478,57479,57492.

Updated by nagachika (Tomoyuki Chikanaga) about 2 years ago

  • Backport changed from 2.1: UNKNOWN, 2.2: DONE, 2.3: REQUIRED, 2.4: DONE to 2.1: UNKNOWN, 2.2: DONE, 2.3: DONE, 2.4: DONE

ruby_2_3 r58164 merged revision(s) 57492.

Also available in: Atom PDF