On Thu, 10 May 2007 15:40:57 +0900, Sylvain Joyeux <sylvain.joyeux / polytechnique.org> wrote:
> Could you tell us why you think [Thread#raise] is "unsafe" ?
Because you have no control over when the exception is delivered, which may be at the worst possible moment. Even ensure does not provide adequate protection.
Consider what happens with this code if an exception happens to arrive just before the begin block is processed:
@counter += 1
begin
# ... do stuff ...
ensure
@counter -= 1
end
Lest you think there's an easy fix, consider what happens with this second example if an exception arrives after the begin block is entered, but before the counter has been incremented:
begin
@counter += 1
# ... do stuff ...
ensure
@counter -= 1
end
-mental