From: MenTaLguY Date: 2008-03-18T01:30:17+09:00 Subject: Re: Thread#raise, Thread#kill, and timeout.rb are unsafe On Tue, 18 Mar 2008 00:06:47 +0900, Roger Pack wrote: > Tongue in cheek I would say something like > > uninterruptible do > > end > > or > > ensureUninterruptible > > end > > or > > uninterruptible do > # some stuff > handle_exceptions_that_have_been_thrown > end > # where handle_exceptions is where they can all get handled. > Kind of scary still, though. In a language with side-effects, I've become convinced that the only safe way to handle asynchronous exceptions is for code to be uninterruptible by default, and only explicitly allow interrupts at specific points (not broad regions of code). This gets back to the fundamental principle that, in order to write a correct multithreaded program, any interaction between threads needs to be by explicit mutual agreement at specific places. One thread needs to explicitly initiate the interaction (in this case, by calling Thread#raise), and the other thread needs to explicitly accept it (e.g. by calling a method which is known to permit the delivery of any pending interrupts when it is called). Otherwise, the resulting nondeterminism is impossible to control. -mental