Forum: Ruby Documenting Thread#raise, Thread#kill, and timeout.rb as unsafe

416189f9bbb62e0ea0e9f5a9ef88b216?d=identicon&s=25 Glyn Normington (glyn)
on 2013-09-12 10:08
Please refer to https://www.ruby-forum.com/topic/143840 for background.
The consensus in that thread appears to be that Thread#raise,
Thread#kill, and timeout.rb are unsafe.

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?

If such documentation is thought to be worthwhile and we can agree on
suitable wording, I will happily submit a pull request.

Here's a first draft of the wording:

# Warning: this method can produce unpredictable behaviour and its use
# is not recommended.
# See https://www.ruby-forum.com/topic/143840 for more information.
9a45896e48a382fe5c656b8873e0dfcb?d=identicon&s=25 Stu (Guest)
on 2013-09-12 22:06
(Received via mailing list)
Thread from 2008?

Seriously ruby was in 1.8 at the time. Ruby has check and wall already
implemented as well as a bug trac system
4131d2f57a0db2a2b4d9a62bd389fd44?d=identicon&s=25 Tony Arcieri (Guest)
on 2013-09-12 22:36
(Received via mailing list)
On Thu, Sep 12, 2013 at 1:08 AM, Glyn Normington
<lists@ruby-forum.com>wrote:

> Please refer to https://www.ruby-forum.com/topic/143840 for background.
> The consensus in that thread appears to be that Thread#raise,
> Thread#kill, and timeout.rb are unsafe.
>

Yes, they are unsafe. Ruby 2.0 has done some work to try to improve
their
safety at the cost of performance, but they are still unsafe on other
Ruby
VMs, particularly those without a GIL, and are probably still buggy on
Ruby
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.
416189f9bbb62e0ea0e9f5a9ef88b216?d=identicon&s=25 Glyn Normington (glyn)
on 2013-09-13 10:04
Thanks Tony.

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
acceptable.
416189f9bbb62e0ea0e9f5a9ef88b216?d=identicon&s=25 Glyn Normington (glyn)
on 2013-09-13 10:09
Yes, Stu, I know this is an old problem, but that doesn't necessarily
mean it has been fixed. I'm relatively new to Ruby and just trying to
work out how much to trust it.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.