From: MenTaLguY Date: 2007-05-12T06:53:59+09:00 Subject: Re: basic threading question: can ruby use real threads? On Sat, 12 May 2007 03:46:58 +0900, Joel VanderWerf wrote: > This is disturbing. > > Is #timeout inherently unsafe, if it is implemented as a thread, even in > MRI ruby's green threads? Correct. #timeout as presently implemented is NEVER safe to use. > What if there were two kind of ensure clauses, one which is > uninterruptible (to be used only for cleanup that is deterministic) and > one which is interruptible (and not guaranteed to finish)? Nope, that's still not sufficient. The fundamental problem is that other threads can _arbitrarily_ mess with control flow by injecting exceptions via Thread#raise. There's no way to guarantee invariants will be preserved, no matter how clever your ensure implementation is. -mental