On Sat, 12 May 2007 06:43:39 +0900, "Bill Kelly" <billk / cts.com> wrote:
> I'd probably settle for a Thread#raise_asap (or #raise_safe, or
> whatever.)  Because in theory, even though one *could* write
> unfriendly code in an ensure block that took a long time to execute; in
> practice all the ensure blocks I can recall seeing were doing what
> appeared to be very simple, deterministic cleanup.

No, that's still not sufficient.  If an exception can be injected at an arbitrary point by an external source, there's simply no way to write sane code.

The only safe model for inter-thread communication is one where both participants agree to communicate.  You'd need something like a Thread#receive_exception that was explicitly called on the receiving side -- of course, that's not too helpful for the purposes to which Thread#raise is usually put.

The fundamental problem is really that most of Ruby's blocking operations don't have allowance for timeout built into their API, which is particularly sad since they're all built on top of select (in MRI, anyway) and that would be really easy to do.  The whole #timeout thing is an unsafe workaround which can never be made safe by its very nature.

-mental