aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-28 15:25:30 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-28 15:25:30 +0000
commit8c0305cf1a86ad22f70d6c52a0ae085492db4084 (patch)
treefc0f062ace8b21d6776edb84312d43148799ce82
parent478770b81a1839d17de0c75edbb84bc937d97f91 (diff)
downloadruby-8c0305cf1a86ad22f70d6c52a0ae085492db4084.tar.gz
introduce rb_fiber_t::first_proc.
* cont.c (rb_fiber_t): add rb_fiber_t::first_proc and do not use rb_thread_t::first_proc which should be thread local. [Bug #13689] * test/ruby/test_thread.rb: test for [Bug #13689]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59200 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--cont.c11
-rw-r--r--test/ruby/test_thread.rb13
2 files changed, 18 insertions, 6 deletions
diff --git a/cont.c b/cont.c
index 32a4aa57b6..095cc86767 100644
--- a/cont.c
+++ b/cont.c
@@ -125,6 +125,7 @@ static machine_stack_cache_t terminated_machine_stack;
struct rb_fiber_struct {
rb_context_t cont;
+ VALUE first_proc;
struct rb_fiber_struct *prev;
enum fiber_status status;
/* If a fiber invokes "transfer",
@@ -308,6 +309,7 @@ fiber_mark(void *ptr)
{
rb_fiber_t *fib = ptr;
RUBY_MARK_ENTER("cont");
+ rb_gc_mark(fib->first_proc);
rb_fiber_mark_self(fib->prev);
cont_mark(&fib->cont);
RUBY_MARK_LEAVE("cont");
@@ -412,7 +414,6 @@ cont_save_thread(rb_context_t *cont, rb_thread_t *th)
/* save thread context */
sth->ec = th->ec;
- sth->first_proc = th->first_proc;
/* saved_thread->machine.stack_(start|end) should be NULL */
/* because it may happen GC afterward */
@@ -555,8 +556,6 @@ cont_restore_thread(rb_context_t *cont)
th->fiber = (rb_fiber_t*)cont;
}
- th->first_proc = sth->first_proc;
-
VM_ASSERT(sth->status == THREAD_RUNNABLE);
}
@@ -1217,7 +1216,7 @@ fiber_init(VALUE fibval, VALUE proc)
th->ec.local_storage_recursive_hash = Qnil;
th->ec.local_storage_recursive_hash_for_trace = Qnil;
- th->first_proc = proc;
+ fib->first_proc = proc;
#if !FIBER_USE_NATIVE
MEMCPY(&cont->jmpbuf, &cth->root_jmpbuf, rb_jmpbuf_t, 1);
@@ -1254,11 +1253,11 @@ rb_fiber_start(void)
rb_context_t *cont = &VAR_FROM_MEMORY(fib)->cont;
int argc;
const VALUE *argv, args = cont->value;
- GetProcPtr(cont->saved_thread.first_proc, proc);
+ GetProcPtr(fib->first_proc, proc);
argv = (argc = cont->argc) > 1 ? RARRAY_CONST_PTR(args) : &args;
cont->value = Qnil;
th->ec.errinfo = Qnil;
- th->ec.root_lep = rb_vm_proc_local_ep(cont->saved_thread.first_proc);
+ th->ec.root_lep = rb_vm_proc_local_ep(fib->first_proc);
th->ec.root_svar = Qfalse;
fib->status = FIBER_RUNNING;
diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb
index 529c52f4ba..dbe4ac21b9 100644
--- a/test/ruby/test_thread.rb
+++ b/test/ruby/test_thread.rb
@@ -34,6 +34,19 @@ class TestThread < Test::Unit::TestCase
th.join
end
+ def test_inspect_with_fiber
+ inspect1 = inspect2 = nil
+
+ Thread.new{
+ inspect1 = Thread.current.inspect
+ Fiber.new{
+ inspect2 = Thread.current.inspect
+ }.resume
+ }.join
+
+ assert_equal inspect1, inspect2, '[Bug #13689]'
+ end
+
def test_main_thread_variable_in_enumerator
assert_equal Thread.main, Thread.current