Yes, they are unsafe. Ruby 2.0 has done some work to try to improve
safety at the cost of performance, but they are still unsafe on other
VMs, particularly those without a GIL, and are probably still buggy on
2.0 as well.
Aside from the issue of providing safe alternatives, would it not be a
great service to the Ruby community, especially newcomers, to document
this lack of safety in the relevant classes?
Considering the work that has gone into features like
Thread.handle_interrupt, ruby-core is probably unlikely to accept such a
label, although it would probably make sense.
I think the difficulty with Thread.handle_interrupt is that it, or
something similar, would need to be used correctly across Ruby’s class
libraries, e.g. in the networking classes, in order for Thread#raise,
thread#kill and timeout.rb to be safe for general use. I couldn’t see
any evidence of such activity in the last couple of years in https://github.com/ruby/ruby, although maybe I was unlucky in my search.
Perhaps the majority of the libraries had already been written with
timeout.rb’s limitations in mind, but it’s hard to know.
But I take the point that the blanket warning is not likely to be