From: Charles Oliver Nutter Date: 2007-12-27T01:16:04+09:00 Subject: Re: Experimental PATCH to improve thread performance Brent Roman wrote: > Even so, > I'm not convinced that Ruby's Thread.stop is unsafe, > because, unlike Java's, Ruby's Thread.stop method > can only act on the currently executing thread. > One cannot stop another Ruby thread. > A Ruby thread can only stop itself. You are correct, I confused myself here. I tend to mix up kill and stop. Stop is safe. > Further, I believe that thread#raise (and even the non-bang > variants exit, kill and terminate) can be made > safe by adding an exception queue > and an "interruptible" flag to each Ruby thread. > This may provide Ruby thread safety without > breaking most existing threaded applications. ... > Do you think there's any merit to this approach? > Any obvious (or not to obvious) holes in it? The only hole I can think of is that even if a thread was marked interruptible, you still would run the risk of raising an exception in ot at a bad time: begin f = File.open # do something with file ensure # what happens if we raise here? f.close end No amount of marking the thread interruptible would ever make it safe to raise in it arbitrarily since it would never be possible to ensure anything. Or perhaps I'm not seeing how your idea prevents this? - Charlie