News for hackers. Stuff that matters.
Re:Why Ruby's Timeout is dangerous (and Thread.raise is terr... by Sonata on Monday June 03, 2024 @01:32PM (#40565031)
The approach taken to this problem by Cats Effect (a Scala concurrency library) is interesting. It allows cancellation of a fiber from outside, but let's blocks of code be marked as uncancelable. If a fiber is cancelled while executing one of these blocks, it will complete the block before cancelling. This protects against cancellation in between two operations which leaves the program in a broken state.

The drawback of this approach is that the onus is on anybody writing code which might be cancelled to correctly mark the uncancelable regions.

Re:Why Ruby's Timeout is dangerous (and Thread.raise is terr... by mrkeen on Monday June 03, 2024 @03:46PM (#40566751)
I don't think you can do better than this.

There's a fundamental tension between 'stop now' and 'close your file handles before stopping'.

Re:Why Ruby's Timeout is dangerous (and Thread.raise is terr... by shirogane86x on Wednesday June 05, 2024 @03:43PM (#40589591)
From how you describe it, it sounds like it's taken the same approach as Haskell's async exceptions + mask/uninterruptibleMask, which to me seems like one of the best solutions around, so props to them