|
|
|
|
|
by cesarb
2281 days ago
|
|
> If you don't want a panic to take down the whole system, you can isolate the code in a thread and use a supervision tree, or use `catch_unwind` to let the thread perform cleanup and then continue from a known state. Playing devil's advocate: with unwinding panics (which are necessary for these two approaches), it's harder to make sure all the data structures the thread was using are left in a coherent state. It's not as bad as exception safety in C++, but it does have some similarities. Just take a look at the tricks the Rust standard library uses to keep everything sane even if the stack unwinds (structs implementing Drop normally called SomethingOnDrop, for instance CopyOnDrop), or std::sync::Mutex poisoning. |
|
Unwind safety is a real issue. I have some personal experience with fixing panic-safety issues in unsafe Rust code:
https://github.com/servo/rust-smallvec/pull/103
I wrote a bit more about it here:
https://users.rust-lang.org/t/c-pitfalls-hard-to-avoid-that-...