Project

General

Profile

Bug #17568

Updated by nobu (Nobuyoshi Nakada) about 3 years ago

`Thread.handle_interrupt` Thread.handle_interrupt and the pending interrupts is currently kept as state on the thread (`rb_thread_t`). (rb_thread_t). 
 However, that seems potentially confusing when `Fiber`s Fibers are used. 

 For instance, this innocent-looking `Fiber` Fiber will forever disable interrupts in the main thread: 
 ```ruby 
 main_thread = Thread.current 

 never_die = Fiber.new do 
   Thread.handle_interrupt(RuntimeError => :never) do 
     Fiber.yield 
   end 
 end 

 begin 
   Thread.new { main_thread.raise "interrupt1" }.join 
 rescue => e 
   puts "raised: #{e}" 
 end 

 never_die.resume 

 Thread.new { main_thread.raise "interrupt2" }.join 

 Thread.new { main_thread.raise "interrupt3" }.join 

 p :after 
 ``` 

 Output is: 
 ``` 
 raised: interrupt1 
 :after 
 ``` 

 (I noticed these weird semantics when implementing `Thread.handle_interrupt` on TruffleRuby, and got a fairly subtle bug due to multiple `Fiber`s Fibers of the same `Thread` Thread queuing the same interrupt multiple times in the `Thread`'s Thread's interrupt queue).

Back