diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-11 18:45:34 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-11 18:45:34 +0000 |
commit | 0c72a8f091eff82b71e045fc8049406d0a48ee85 (patch) | |
tree | a07b21c70d81d5b28fafca7a986768dc006fabe0 | |
parent | 9258462e2a2dadaf82e3b657400eeb94c457700b (diff) |
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
-rw-r--r-- | test/thread/test_queue.rb | 17 | ||||
-rw-r--r-- | thread.c | 14 | ||||
-rw-r--r-- | thread_sync.c | 4 | ||||
-rw-r--r-- | version.h | 2 |
4 files changed, 31 insertions, 6 deletions
diff --git a/test/thread/test_queue.rb b/test/thread/test_queue.rb index e1821da0de..6122d9b87c 100644 --- a/test/thread/test_queue.rb +++ b/test/thread/test_queue.rb @@ -547,4 +547,21 @@ class TestQueue < Test::Unit::TestCase # don't leak this thread assert_nothing_raised{counter.join} end + + def test_queue_with_trap + assert_in_out_err([], <<-INPUT, %w(USR2 USR2 exit), []) + q = Queue.new + trap(:USR2){ + q.push 'USR2' + } + Thread.new{ + loop{ + Process.kill :USR2, $$ + } + } + puts q.pop + puts q.pop + puts 'exit' + INPUT + end end @@ -85,6 +85,7 @@ static ID id_locals; static void sleep_timeval(rb_thread_t *th, struct timeval time, int spurious_check); static void sleep_wait_for_interrupt(rb_thread_t *th, double sleepsec, int spurious_check); static void sleep_forever(rb_thread_t *th, int nodeadlock, int spurious_check); +static void rb_thread_sleep_deadly_allow_spurious_wakeup(void); static double timeofday(void); static int rb_threadptr_dead(rb_thread_t *th); static void rb_check_deadlock(rb_vm_t *vm); @@ -845,7 +846,7 @@ thread_join_sleep(VALUE arg) while (target_th->status != THREAD_KILLED) { if (forever) { - sleep_forever(th, 1, 0); + sleep_forever(th, TRUE, FALSE); } else { double now = timeofday(); @@ -1136,14 +1137,21 @@ void rb_thread_sleep_forever(void) { thread_debug("rb_thread_sleep_forever\n"); - sleep_forever(GET_THREAD(), 0, 1); + sleep_forever(GET_THREAD(), FALSE, TRUE); } void rb_thread_sleep_deadly(void) { thread_debug("rb_thread_sleep_deadly\n"); - sleep_forever(GET_THREAD(), 1, 1); + sleep_forever(GET_THREAD(), TRUE, TRUE); +} + +static void +rb_thread_sleep_deadly_allow_spurious_wakeup(void) +{ + thread_debug("rb_thread_sleep_deadly_allow_spurious_wakeup\n"); + sleep_forever(GET_THREAD(), TRUE, FALSE); } static double diff --git a/thread_sync.c b/thread_sync.c index 8869af2deb..152995fac0 100644 --- a/thread_sync.c +++ b/thread_sync.c @@ -420,7 +420,7 @@ rb_mutex_abandon_all(rb_mutex_t *mutexes) static VALUE rb_mutex_sleep_forever(VALUE time) { - sleep_forever(GET_THREAD(), 1, 0); /* permit spurious check */ + rb_thread_sleep_deadly_allow_spurious_wakeup(); return Qnil; } @@ -773,7 +773,7 @@ queue_delete_from_waiting(struct waiting_delete *p) static VALUE queue_sleep(VALUE arg) { - rb_thread_sleep_deadly(); + rb_thread_sleep_deadly_allow_spurious_wakeup(); return Qnil; } @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.4.0" #define RUBY_RELEASE_DATE "2017-03-12" -#define RUBY_PATCHLEVEL 44 +#define RUBY_PATCHLEVEL 45 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 3 |