From: MenTaLguY Date: 2008-03-20T03:50:13+09:00 Subject: Re: Thread#raise, Thread#kill, and timeout.rb are unsafe On Thu, 20 Mar 2008 02:29:09 +0900, Paul Brannan wrote: > On Tue, Mar 18, 2008 at 02:04:40PM +0900, Tanaka Akira wrote: >> It is because Thread.check_interrupt with blocking operations causes >> race conditions. > > Raising an exception during a blocking write operation makes it > impossible to know how much data was written. > > Similarly, raising an exception during a blocking read operation makes > it impossible to access the data that was read. > > The same is true for any operation for which partial success is > possible. That's a good point. To some extent it is an API design and implementation problem; an API which can partially "succeed" in that fashion is arguably flawed. There are really two alternatives: 1. fix the operation so that it succeeds or fails atomically 2. otherwise, make the operation always non-interruptable (Well, there is also a third solution, used by Java's NIO for blocking reads and writes: on interrupt, destroy the object in question so that it doesn't matter anymore. But I don't think it's a particularly good solution.) -mental