From 87d48d14a0839316f051bddd4d794bdd64e49181 Mon Sep 17 00:00:00 2001 From: ko1 Date: Fri, 21 Dec 2012 09:33:44 +0000 Subject: * vm_core.h, vm_trace.c: fix multi-threading bug for tracing. Move `trace_arg' from rb_tp_t::trace_arg to rb_thread_t::trace_arg. `trace_arg' may changed by multiple threads. rb_thread_t::trace_arg can represent rb_thread_t::trace_running (null or non-null) and rb_thread_t::trace_running is removed. After that, `rb_tp_t' is not needed to check tracing or not (A running thread knows tracing or not). This is why I remove tp_attr_check_active() and make new function get_trace_arg(). And this modification disable to work the following code: TracePoint.trace{|tp| Thread.new{p tp.event} # access `tp' from other threads. } I believe nobody mix threads at trace procedure. This is current limitation. * cont.c (fiber_switch, rb_cont_call): use rb_thread_t::trace_arg instead of rb_thread_t::trace_running. * test/ruby/test_settracefunc.rb: add a multi-threading test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38524 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_settracefunc.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb index f4975cd333..a9054378c8 100644 --- a/test/ruby/test_settracefunc.rb +++ b/test/ruby/test_settracefunc.rb @@ -829,4 +829,23 @@ class TestSetTraceFunc < Test::Unit::TestCase assert_normal_exit('def m; end; TracePoint.new(:return) {raise}.enable {m}', '', timeout: 3) end end + + def test_tracepoint_with_multithreads + assert_nothing_raised do + TracePoint.new{ + 10.times{ + Thread.pass + } + }.enable do + (1..10).map{ + Thread.new{ + 1000.times{ + } + } + }.each{|th| + th.join + } + end + end + end end -- cgit v1.2.3