From: MenTaLguY Date: 2008-03-19T03:09:33+09:00 Subject: Re: Thread#raise, Thread#kill, and timeout.rb are unsafe On Tue, 18 Mar 2008 14:04:40 +0900, Tanaka Akira wrote: > Basically, asynchronous events should be queued. > > * make a queue for each thread. > * Thread#raise(exc) enqueue exc to the queue. > * Thread.check_interrupt(klass) checks an exception which is > a kind of klass in the queue of the current thread. If it > exists, the exception is raised. > * other queue examining mechanism, such as sigpending, etc, > may be useful. > > Thread.check_interrupt is a safe point. > > However safe points is not only Thread.check_interrupt. > Blocking operations, such as I/O, may or may not be safe > points. It is because Thread.check_interrupt with blocking > operations causes race conditions. So application must > choose that make a blocking operation interruption safe or > uninterruptible. > > * Thread.blocking_interruptible(klass) { ... } > * Thread.blocking_uninterruptible(klass) { ... } > > Blocking operations in Thread.blocking_interruptible are > safe points. This sounds very good! I hadn't considered anything like blocking_interruptible, but it seems useful. -mental