https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112010-01-07T23:29:00ZRuby Issue Tracking SystemRuby master - Feature #2012: Set event_flags on thread creation if hook existshttps://bugs.ruby-lang.org/issues/2012?journal_id=75642010-01-07T23:29:00Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p>=begin<br>
Hi --</p>
<p>Sorry for very late response!</p>
<p>2009/8/30 Mark Moseley <a href="mailto:redmine@ruby-lang.org" class="email">redmine@ruby-lang.org</a>:</p>
<blockquote>
<p>In ruby-debug, when a user sets a breakpoint that ends up executed by a later-created thread, then nothing will happen.</p>
</blockquote>
<p>Confirmed.</p>
<pre><code> $ ./ruby.org -e '
> set_trace_func(proc {|*a| p a })
> Thread.new { puts "foo" }.join
> '
["c-return", "-e", 2, :set_trace_func, #<Binding:0x824d10c>, Kernel]
["line", "-e", 3, nil, #<Binding:0x824cfe0>, nil]
["c-call", "-e", 3, :new, #<Binding:0x824cf04>, Thread]
["c-call", "-e", 3, :initialize, #<Binding:0x824ce00>, Thread]
["c-return", "-e", 3, :initialize, #<Binding:0x824ccfc>, Thread]
foo
["c-return", "-e", 3, :new, #<Binding:0x824cc0c>, Thread]
["c-call", "-e", 3, :join, #<Binding:0x824cb30>, Thread]
["c-return", "-e", 3, :join, #<Binding:0x824ca54>, Thread]
</code></pre>
<p>("c-call" event to the method `puts' is not found)</p>
<p>This issue affects the coverage feature too. It fails to measure<br>
coverage that is run in sub thread. <a href="https://blade.ruby-lang.org/ruby-dev/39950">[ruby-dev:39950]</a></p>
<blockquote>
<p>I propose adding the following patch to the core:</p>
<a name="Index-threadc"></a>
<h1 >Index: thread.c<a href="#Index-threadc" class="wiki-anchor">¶</a></h1>
<p>--- thread.c (revision 24710)<br>
+++ thread.c (working copy)<br>
@@ -497,6 +497,9 @@<br>
th->thgroup = GET_THREAD()->thgroup;</p>
<pre><code>native_mutex_initialize(&th->interrupt_lock);
</code></pre>
<ul>
<li>if (GET_VM()->event_hooks != NULL)</li>
<li>
<pre><code> th->event_flags |= RUBY_EVENT_VM;
</code></pre>
</li>
<li>/* kick thread */<br>
st_insert(th->vm->living_threads, thval, (st_data_t) th->thread_id);<br>
native_thread_create(th);</li>
</ul>
</blockquote>
<p>Basically I agree with your patch. But it leaves event_flags true<br>
even if all vm-level hooks are removed. How about this patch:</p>
<p>diff --git a/thread.c b/thread.c<br>
index 0ba41c7..c082471 100644<br>
--- a/thread.c<br>
+++ b/thread.c<br>
@@ -531,6 +531,9 @@ thread_create_core(VALUE thval, VALUE args, VALUE<br>
(*fn)(ANYARGS))<br>
th->thgroup = GET_THREAD()->thgroup;</p>
<pre><code> native_mutex_initialize(&th->interrupt_lock);
</code></pre>
<ul>
<li>if (GET_VM()->event_hooks != NULL)</li>
<li>th->event_flags |= RUBY_EVENT_VM;</li>
<li>/* kick thread */<br>
st_insert(th->vm->living_threads, thval, (st_data_t) th->thread_id);<br>
err = native_thread_create(th);<br>
@@ -3750,7 +3753,12 @@ rb_threadptr_exec_event_hooks(rb_thread_t *th,<br>
rb_event_flag_t flag, VALUE self,<br>
exec_event_hooks(th->event_hooks, flag, self, id, klass);<br>
}<br>
if (wait_event & RUBY_EVENT_VM) {</li>
</ul>
<ul>
<li>exec_event_hooks(th->vm->event_hooks, flag, self, id, klass);</li>
</ul>
<ul>
<li>if (th->vm->event_hooks == NULL) {</li>
<li>
<pre><code> th->event_flags &= (~RUBY_EVENT_VM);
</code></pre>
</li>
<li>}</li>
<li>else {</li>
<li>
<pre><code> exec_event_hooks(th->vm->event_hooks, flag, self, id, klass);
</code></pre>
</li>
<li>}<br>
}<br>
th->errinfo = errinfo;<br>
}</li>
</ul>
<p>--<br>
Yusuke ENDOH <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a></p>
<p>=end</p> Ruby master - Feature #2012: Set event_flags on thread creation if hook existshttps://bugs.ruby-lang.org/issues/2012?journal_id=76322010-01-12T02:31:34Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Category</strong> set to <i>core</i></li><li><strong>Assignee</strong> set to <i>ko1 (Koichi Sasada)</i></li></ul><p>=begin</p>
<p>=end</p> Ruby master - Feature #2012: Set event_flags on thread creation if hook existshttps://bugs.ruby-lang.org/issues/2012?journal_id=79702010-01-28T11:57:10Zrogerdpack (Roger Pack)rogerpack2005@gmail.com
<ul></ul><p>=begin<br>
This patch seems to fix the threading difficulties for ruby-prof as well.</p>
<p>Koichi could you take a look at it sometime?</p>
<p>-r<br>
=end</p> Ruby master - Feature #2012: Set event_flags on thread creation if hook existshttps://bugs.ruby-lang.org/issues/2012?journal_id=92602010-03-24T23:57:05Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>=begin<br>
This issue was solved with changeset r27033.<br>
Mark, thank you for reporting this issue.<br>
Your contribution to Ruby is greatly appreciated.<br>
May Ruby be with you.</p>
<p>=end</p> Ruby master - Feature #2012: Set event_flags on thread creation if hook existshttps://bugs.ruby-lang.org/issues/2012?journal_id=92612010-03-25T00:19:51Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p>=begin<br>
Hi,</p>
<p>2010/1/7 Yusuke ENDOH <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a>:</p>
<blockquote>
<p>2009/8/30 Mark Moseley <a href="mailto:redmine@ruby-lang.org" class="email">redmine@ruby-lang.org</a>:</p>
<blockquote>
<p>In ruby-debug, when a user sets a breakpoint that ends up executed by a later-created thread, then nothing will happen.</p>
</blockquote>
</blockquote>
<p>I've committed the patch I wrote (<a href="https://blade.ruby-lang.org/ruby-core/27471">[ruby-core:27471]</a>).</p>
<p>I believe that this is certainly a bug and my patch is benign,<br>
but I'm happy to revert it if ko1 disagree.</p>
<p>--<br>
Yusuke ENDOH <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a></p>
<p>=end</p>