зеркало из https://github.com/github/ruby.git
* thread.c (thread_start_func_2): don't interrupt when last thread exit
unless main thread is already exited. Otherwise main thread could be wrongly interrupted when it uses rb_thread_call_without_gvl(). Patch by Takehiro Kubo. [Bug #11237][ruby-dev:49044][GH-898] * test/-ext-/gvl/test_last_thread.rb: new test for the above fix. * ext/-test-/gvl/call_without_gvl/call_without_gvl.c: new ext for the above test. * ext/-test-/gvl/call_without_gvl/extconf.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50900 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
95f251b465
Коммит
8ecd3b7114
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
|||
Sat Jun 13 07:21:18 2015 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||
|
||||
* thread.c (thread_start_func_2): don't interrupt when last thread
|
||||
exit unless main thread is already exited. Otherwise main thread
|
||||
could be wrongly interrupted when it uses rb_thread_call_without_gvl().
|
||||
Patch by Takehiro Kubo. [Bug #11237][ruby-dev:49044][GH-898]
|
||||
|
||||
* test/-ext-/gvl/test_last_thread.rb: new test for the above fix.
|
||||
|
||||
* ext/-test-/gvl/call_without_gvl/call_without_gvl.c: new ext for
|
||||
the above test.
|
||||
* ext/-test-/gvl/call_without_gvl/extconf.rb: ditto.
|
||||
|
||||
Mon Jun 15 00:14:33 2015 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* ext/pathname/lib/pathname.rb (descend): Blockless form supported.
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
#include "ruby/ruby.h"
|
||||
#include "ruby/thread.h"
|
||||
#include <sys/select.h>
|
||||
|
||||
static void*
|
||||
native_sleep_callback(void *data)
|
||||
{
|
||||
struct timeval *timeval = data;
|
||||
select(0, NULL, NULL, NULL, timeval);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static VALUE
|
||||
thread_runnable_sleep(VALUE thread, VALUE timeout)
|
||||
{
|
||||
struct timeval timeval;
|
||||
|
||||
if (NIL_P(timeout)) {
|
||||
rb_raise(rb_eArgError, "timeout must be non nil");
|
||||
}
|
||||
|
||||
timeval = rb_time_interval(timeout);
|
||||
|
||||
rb_thread_call_without_gvl(native_sleep_callback, &timeval, RUBY_UBF_IO, NULL);
|
||||
|
||||
return thread;
|
||||
}
|
||||
|
||||
void
|
||||
Init_call_without_gvl(void)
|
||||
{
|
||||
rb_define_method(rb_cThread, "__runnable_sleep__", thread_runnable_sleep, 1);
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
create_makefile("-test-/gvl/call_without_gvl")
|
|
@ -0,0 +1,22 @@
|
|||
class TestLastThread < Test::Unit::TestCase
|
||||
|
||||
# [Bug #11237]
|
||||
def test_last_thread
|
||||
|
||||
assert_separately([], <<-"end;") #do
|
||||
require '-test-/gvl/call_without_gvl'
|
||||
|
||||
Thread.new {
|
||||
sleep 0.2
|
||||
}
|
||||
|
||||
t0 = Time.now
|
||||
Thread.current.__runnable_sleep__ 1
|
||||
t1 = Time.now
|
||||
t = t1 - t0
|
||||
|
||||
assert_operator(t, :>=, 1)
|
||||
end;
|
||||
end
|
||||
end
|
||||
|
2
thread.c
2
thread.c
|
@ -629,7 +629,7 @@ thread_start_func_2(rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_s
|
|||
|
||||
/* delete self other than main thread from living_threads */
|
||||
rb_vm_living_threads_remove(th->vm, th);
|
||||
if (rb_thread_alone()) {
|
||||
if (main_th->status == THREAD_KILLED && rb_thread_alone()) {
|
||||
/* I'm last thread. wake up main thread from rb_thread_terminate_all */
|
||||
rb_threadptr_interrupt(main_th);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче