From: MenTaLguY Date: 2008-03-19T02:52:17+09:00 Subject: Re: Thread#raise, Thread#kill, and timeout.rb are unsafe On Wed, 19 Mar 2008 00:20:54 +0900, ara howard wrote: >> Probably. Does anyone have any idea? > > > Thread.current.raises do |exception| > queue.push exception > end > > .... > > even_loop do > stuff > if exception = queue.pop > ... > end > end > > seems like it would address a ton of issued without overly > complicating ruby's internals - just provide an 'on raise' handler. How do you plan on protecting against non-determinism introduced by the "on raise" handler? For example, if queue were a user-implemented data structure, and the handler fired in the middle of queue.pop? If queue.pop is not protected by a lock, there is potential to corrupt the queue object. If it is protected by a lock, there is potential for deadlock. (This is basically the same issue as asynchronous signal safety.) I think the only way around this is for the receiving thread to explicitly choose moments when it wants to receive any pending asynchronous exceptions. Can you think of another way? -mental