From: Joel VanderWerf Date: 2007-05-12T07:08:05+09:00 Subject: Re: basic threading question: can ruby use real threads? MenTaLguY wrote: ... >> 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. But what if we limit that arbitrary power by adding a new construct? Suppose thread1 is executing this code: begin ensure_uninterruptible # not in ruby yet # quick and deterministic cleanup code end and suppose that thread2 does this: thread1.raise Can't we implement ensure_uninterruptible in such a way that thread1.raise waits until thread1 finishes the clause (or maybe raises an error in thread2 instead of in thread1)? I'm not sure it's a good idea, but is there a reason it couldn't be done with green threads? -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407