* [ruby-core:103306] [Ruby master Bug#15735] Thread#handle_interrupt does not prevent Thread#kill from interrupting
[not found] <redmine.issue-15735.20190328184622.22321@ruby-lang.org>
@ 2021-04-08 15:11 ` merch-redmine
0 siblings, 0 replies; only message in thread
From: merch-redmine @ 2021-04-08 15:11 UTC (permalink / raw)
To: ruby-core
Issue #15735 has been updated by jeremyevans0 (Jeremy Evans).
I've determined this is just a documentation issue, and there is a way for `Thread.handle_interrupt` to handle kill/terminate interrupts, which I've committed.
If we handle to allow `Exception` to include these interrupts, we could do something like this:
```diff
--- a/thread.c
+++ b/thread.c
@@ -1992,6 +1992,7 @@ rb_threadptr_pending_interrupt_check_mask(rb_thread_t *th, VALUE err)
VALUE mod;
long i;
+ retry:
for (i=0; i<mask_stack_len; i++) {
mask = mask_stack[mask_stack_len-(i+1)];
@@ -2023,6 +2024,15 @@ rb_threadptr_pending_interrupt_check_mask(rb_thread_t *th, VALUE err)
}
/* try to next mask */
}
+
+ /* eKillSignal and eTerminateSignal are Integers, but should be
+ * rescued if using Exception in Thread.handle_interrupt.
+ */
+ if (err == rb_cInteger) {
+ err = rb_eException;
+ goto retry;
+ }
+
return INTERRUPT_NONE;
}
```
----------------------------------------
Bug #15735: Thread#handle_interrupt does not prevent Thread#kill from interrupting
https://bugs.ruby-lang.org/issues/15735#change-91391
* Author: inoueyu (Yuki INOUE)
* Status: Closed
* Priority: Normal
* ruby -v: 2.6.2p47 (2019-03-13 revision 67232) [x86_64-darwin18]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
https://docs.ruby-lang.org/en/trunk/Thread.html#method-c-handle_interrupt
According to the documentation above, `Thread#handle_interrupt(Exception => :never)` would prevent the interrupts from `Thread#kill`.
In the following code, however, the `Thread#kill` seems to just kill the thread immediately even if the thread is instructed to never handle interrupt.
``` ruby
t = Thread.new do
Thread.handle_interrupt(Exception => :never) do
puts "thread started"
sleep 2
puts "thread end"
end
end
sleep 1
t.kill
puts "main end"
sleep 2
```
Outputs
```
$ ruby test.rb
thread started
main end
$
```
Is the document wrong? Or, implementation not working as expected?
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-04-08 15:11 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <redmine.issue-15735.20190328184622.22321@ruby-lang.org>
2021-04-08 15:11 ` [ruby-core:103306] [Ruby master Bug#15735] Thread#handle_interrupt does not prevent Thread#kill from interrupting merch-redmine
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).