mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Make Ractor stdio belonging to the Ractor [Bug #17672]
Defer making ractor stdio until ractor started. Before ractor started, created objects belong to the caller ractor instead of the created ractor.
This commit is contained in:
parent
8ccc12118e
commit
b3c53a8a88
Notes:
git
2021-03-07 00:59:00 +09:00
Merged: https://github.com/ruby/ruby/pull/4241 Merged-By: nobu <nobu@ruby-lang.org>
3 changed files with 21 additions and 9 deletions
|
@ -805,6 +805,18 @@ assert_equal 'ok', %q{
|
||||||
'ok'
|
'ok'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# $stdin,out,err belong to Ractor
|
||||||
|
assert_equal 'ok', %q{
|
||||||
|
r = Ractor.new do
|
||||||
|
$stdin.itself
|
||||||
|
$stdout.itself
|
||||||
|
$stderr.itself
|
||||||
|
'ok'
|
||||||
|
end
|
||||||
|
|
||||||
|
r.take
|
||||||
|
}
|
||||||
|
|
||||||
# $DEBUG, $VERBOSE are Ractor local
|
# $DEBUG, $VERBOSE are Ractor local
|
||||||
assert_equal 'true', %q{
|
assert_equal 'true', %q{
|
||||||
$DEBUG = true
|
$DEBUG = true
|
||||||
|
|
9
ractor.c
9
ractor.c
|
@ -1583,11 +1583,6 @@ rb_ractor_main_setup(rb_vm_t *vm, rb_ractor_t *r, rb_thread_t *th)
|
||||||
rb_ractor_living_threads_insert(r, th);
|
rb_ractor_living_threads_insert(r, th);
|
||||||
}
|
}
|
||||||
|
|
||||||
// io.c
|
|
||||||
VALUE rb_io_prep_stdin(void);
|
|
||||||
VALUE rb_io_prep_stdout(void);
|
|
||||||
VALUE rb_io_prep_stderr(void);
|
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
ractor_create(rb_execution_context_t *ec, VALUE self, VALUE loc, VALUE name, VALUE args, VALUE block)
|
ractor_create(rb_execution_context_t *ec, VALUE self, VALUE loc, VALUE name, VALUE args, VALUE block)
|
||||||
{
|
{
|
||||||
|
@ -1599,10 +1594,6 @@ ractor_create(rb_execution_context_t *ec, VALUE self, VALUE loc, VALUE name, VAL
|
||||||
r->pub.id = ractor_next_id();
|
r->pub.id = ractor_next_id();
|
||||||
RUBY_DEBUG_LOG("r:%u", r->pub.id);
|
RUBY_DEBUG_LOG("r:%u", r->pub.id);
|
||||||
|
|
||||||
r->r_stdin = rb_io_prep_stdin();
|
|
||||||
r->r_stdout = rb_io_prep_stdout();
|
|
||||||
r->r_stderr = rb_io_prep_stderr();
|
|
||||||
|
|
||||||
rb_ractor_t *cr = rb_ec_ractor_ptr(ec);
|
rb_ractor_t *cr = rb_ec_ractor_ptr(ec);
|
||||||
r->verbose = cr->verbose;
|
r->verbose = cr->verbose;
|
||||||
r->debug = cr->debug;
|
r->debug = cr->debug;
|
||||||
|
|
9
thread.c
9
thread.c
|
@ -777,6 +777,11 @@ thread_do_start(rb_thread_t *th)
|
||||||
|
|
||||||
void rb_ec_clear_current_thread_trace_func(const rb_execution_context_t *ec);
|
void rb_ec_clear_current_thread_trace_func(const rb_execution_context_t *ec);
|
||||||
|
|
||||||
|
// io.c
|
||||||
|
VALUE rb_io_prep_stdin(void);
|
||||||
|
VALUE rb_io_prep_stdout(void);
|
||||||
|
VALUE rb_io_prep_stderr(void);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
thread_start_func_2(rb_thread_t *th, VALUE *stack_start)
|
thread_start_func_2(rb_thread_t *th, VALUE *stack_start)
|
||||||
{
|
{
|
||||||
|
@ -799,6 +804,10 @@ thread_start_func_2(rb_thread_t *th, VALUE *stack_start)
|
||||||
RB_VM_LOCK();
|
RB_VM_LOCK();
|
||||||
{
|
{
|
||||||
rb_vm_ractor_blocking_cnt_dec(th->vm, th->ractor, __FILE__, __LINE__);
|
rb_vm_ractor_blocking_cnt_dec(th->vm, th->ractor, __FILE__, __LINE__);
|
||||||
|
rb_ractor_t *r = th->ractor;
|
||||||
|
r->r_stdin = rb_io_prep_stdin();
|
||||||
|
r->r_stdout = rb_io_prep_stdout();
|
||||||
|
r->r_stderr = rb_io_prep_stderr();
|
||||||
}
|
}
|
||||||
RB_VM_UNLOCK();
|
RB_VM_UNLOCK();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue