mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
8ecd3b7114
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
35 lines
670 B
C
35 lines
670 B
C
#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);
|
|
}
|