From: Charles Oliver Nutter Date: 2007-12-23T04:21:53+09:00 Subject: Re: Experimental PATCH to improve thread performance Sylvain Joyeux wrote: > On Sat, Dec 22, 2007 at 11:07:25PM +0900, Charles Oliver Nutter wrote: >> Provably unsafe thread operations Ruby supports and should not: >> >> stop >> exit/exit!/kill/kill!/terminate/terminate! >> raise > Is #raise unsafe if done at checkpoints ? (i.e. raising a thread which > is waiting for a condition variable) I'm not sure if you mean checkpoints in your code or checkpoints in e.g. JRuby. The latter doesn't improve the safety of raise in any way...the former, well I suppose it would depend on whether the code that's waiting for some condition variable is prepared to have an exception raised at that point. raise is unsafe for two reasons: 1. it causes the target thread to raise exceptions it may not be prepared to handle 2. it could raise within an ensure block that's cleaning up resources or locks It's also interesting to note that the timeout stdlib is totally unsafe because it uses both kill AND raise at various times. timeout should *not* be used, and yet it's used by net/protocol to timeout individual packets. There's an open task in JRuby to reimplement net/protocol to not use timeout, and instead use nonblocking IO and selectors. One of these days... The rule of thumb is basically this: don't allow changing the path of a given thread unless that thread is expecting a path change. - Charlie