summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-17 08:26:17 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-17 08:26:17 +0000
commitdb9523ef47c9bdc895803a12690713bf49379051 (patch)
tree1829cf9577832ae78e2f4c34e23ce3fe6ba3cb11 /thread.c
parent78cc1491d5dd106af94edd91b3ca4698423daaf7 (diff)
thread.c: fix overly long Thread#join w/ timeout
* test/ruby/test_thread.rb (test_signal_at_join): test with timeout * thread.c (sleep_wait_for_interrupt): remove (thread_join_sleep): use native_sleep directly to avoid extra missing thread status change [Bug #14181] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61302 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/thread.c b/thread.c
index d896a1b04b..e70f29e4f7 100644
--- a/thread.c
+++ b/thread.c
@@ -91,7 +91,6 @@ static VALUE sym_never;
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);
@@ -888,18 +887,22 @@ thread_join_sleep(VALUE arg)
rb_check_deadlock(th->vm);
native_sleep(th, 0);
th->vm->sleeper--;
- RUBY_VM_CHECK_INTS_BLOCKING(th->ec);
- th->status = THREAD_RUNNABLE;
}
else {
double now = timeofday();
+ struct timeval tv;
+
if (now > limit) {
thread_debug("thread_join: timeout (thid: %"PRI_THREAD_ID")\n",
thread_id_str(target_th));
return Qfalse;
}
- sleep_wait_for_interrupt(th, limit - now, 0);
+ tv = double2timeval(limit - now);
+ th->status = THREAD_STOPPED;
+ native_sleep(th, &tv);
}
+ RUBY_VM_CHECK_INTS_BLOCKING(th->ec);
+ th->status = THREAD_RUNNABLE;
thread_debug("thread_join: interrupted (thid: %"PRI_THREAD_ID", status: %s)\n",
thread_id_str(target_th), thread_status_name(target_th, TRUE));
}
@@ -1231,12 +1234,6 @@ timeofday(void)
}
}
-static void
-sleep_wait_for_interrupt(rb_thread_t *th, double sleepsec, int spurious_check)
-{
- sleep_timeval(th, double2timeval(sleepsec), spurious_check);
-}
-
void
rb_thread_wait_for(struct timeval time)
{