mfarrugi
mfarrugi

Reputation: 179

How to unwind all threads on panic?

What's the least terrible way to implement 'unwind all threads on panic'? I would like to have every thread (attempt to) gracefully die on panics and SIGINTs (and notice SIGKILLs?).

It doesn't appear there is a Rust way to interrupt threads, so I'm thinking that I would implement a trait akin to runOneStep and have my threads check a boolean or look at libc interrupt handling.

I've seen How can I cause a panic on a thread to immediately end the main thread?, which is basically the hacky way of setting panic=abort. I've also seen Thread::cancel() support.

Upvotes: 1

Views: 616

Answers (1)

Bruce David Wilner
Bruce David Wilner

Reputation: 467

You can't do anything graceful on a SIGKILL. That's what SIGKILL means. There's a less austere kill, I think it's called ABORT. (I'm an old-schooler, and I refer to them by their numbers: kill is 9, abort was, I think, 15.)

Upvotes: 3

Related Questions