ruby-changes:65400
From: Nobuyoshi <ko1@a...>
Date: Sun, 7 Mar 2021 00:58:48 +0900 (JST)
Subject: [ruby-changes:65400] b3c53a8a88 (master): Make Ractor stdio belonging to the Ractor [Bug #17672]
https://git.ruby-lang.org/ruby.git/commit/?id=b3c53a8a88 From b3c53a8a885be8f5cc2b712798b0d2741c488ce4 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sun, 7 Mar 2021 00:58:28 +0900 Subject: 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. --- bootstraptest/test_ractor.rb | 12 ++++++++++++ ractor.c | 9 --------- thread.c | 9 +++++++++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb index 69f3337..6299b50 100644 --- a/bootstraptest/test_ractor.rb +++ b/bootstraptest/test_ractor.rb @@ -805,6 +805,18 @@ assert_equal 'ok', %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_ractor.rb#L805 '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 assert_equal 'true', %q{ $DEBUG = true diff --git a/ractor.c b/ractor.c index 292a33b..4cb7b5a 100644 --- a/ractor.c +++ b/ractor.c @@ -1583,11 +1583,6 @@ rb_ractor_main_setup(rb_vm_t *vm, rb_ractor_t *r, rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/ractor.c#L1583 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 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 https://github.com/ruby/ruby/blob/trunk/ractor.c#L1594 r->pub.id = ractor_next_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); r->verbose = cr->verbose; r->debug = cr->debug; diff --git a/thread.c b/thread.c index c600a87..f2dd417 100644 --- a/thread.c +++ b/thread.c @@ -777,6 +777,11 @@ thread_do_start(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/thread.c#L777 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 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) https://github.com/ruby/ruby/blob/trunk/thread.c#L804 RB_VM_LOCK(); { 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(); } -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/