From: Charles Oliver Nutter Date: 2007-12-27T05:27:58+09:00 Subject: Re: Experimental PATCH to improve thread performance Sylvain Joyeux wrote: > On Thu, Dec 27, 2007 at 01:57:22AM +0900, Charles Oliver Nutter wrote: >> Except that requiring users to use synchronization points in order to make >> a feature safe basically means everyone will do it the unsafe way. > What I meant was in the same line of though than Brent's: only act upon > queued exceptions if the thread is inside a synchronization point. That > way, the exception mechanism, without being completely safe, is reduced > to cases where it can be safe. Ensuring that the child thread is able to > understand the exception is another matter altogether: it is the > responsibility of the program designer. Certainly, the feature could be made safe. And in JRuby's internal implementation of Thread#raise, we do exactly that kind of checkpointing to make sure Java "finally" blocks and JRuby runtime structures are not damaged. But there's nothing equivalent in Ruby code; Thread#raise is not safe to use in its current form without additional gymnastics on the user's part. When it finds common use in stdlibs like thread.rb--which many libraries and applications use without *any* sort of checkpointing--the problem is made even worse. >> a clear checkpoint and agreement from both parent and child thread that >> it's ok to raise, you can't *ever* know that a thread is safe to raise in, > Threads are never created out of the void. Threads are created by the > program itself and multi-thread messaging is part of the design of the > whole program. Inter-thread exceptions are a flexible inter-thread error > messaging and I certainly think that removing them altogether would > remove a nice idea from the Ruby language. If made safe and moved toward a more message-passing-like logic, sure. But as it's implemented now, it's broken and dangerous. - Charlie