mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
[ruby/timeout] Gracefully handle a call to ensure_timeout_thread_created in a signal handler
* Fixes the issue described in
https://github.com/ruby/timeout/issues/17#issuecomment-1461498517
for TruffleRuby and JRuby.
* CRuby is currently unable to use Timeout in a signal handler due to
https://bugs.ruby-lang.org/issues/19473.
7a48e1c079
This commit is contained in:
parent
4044188266
commit
3b602c952d
1 changed files with 3 additions and 0 deletions
|
@ -123,6 +123,9 @@ module Timeout
|
||||||
|
|
||||||
def self.ensure_timeout_thread_created
|
def self.ensure_timeout_thread_created
|
||||||
unless @timeout_thread and @timeout_thread.alive?
|
unless @timeout_thread and @timeout_thread.alive?
|
||||||
|
# If the Mutex is already owned we are in a signal handler.
|
||||||
|
# In that case, just return and let the main thread create the @timeout_thread.
|
||||||
|
return if TIMEOUT_THREAD_MUTEX.owned?
|
||||||
TIMEOUT_THREAD_MUTEX.synchronize do
|
TIMEOUT_THREAD_MUTEX.synchronize do
|
||||||
unless @timeout_thread and @timeout_thread.alive?
|
unless @timeout_thread and @timeout_thread.alive?
|
||||||
@timeout_thread = create_timeout_thread
|
@timeout_thread = create_timeout_thread
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue