1

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.

Community
  • 1
  • 1
mfarrugi
  • 178
  • 11
  • 1
    Could you expand a bit more on your goal? Since you've already read the linked Internals forum post, you understand why something like `Thread::cancel` would be a bad idea. What's wrong with just terminating the program? – Shepmaster Jul 30 '16 at 21:23
  • I have cleanup on some threads that I would like to be very confident is run. Having a separate program watch for this one's health would work, but I feel that adds more complexity. This kind of thing in Java would be provided by a ShutDownHook, but that is some runtime magic. – mfarrugi Jul 31 '16 at 23:22

1 Answers1

3

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.)

  • If only there was some resource you could reference to be sure what the signal names and numbers were... ^_^ If OP decides to switch to a different signal, what would be the solution? – Shepmaster Jul 31 '16 at 00:19
  • 1
    OP asks: *gracefully die **on panics** and sigkills* (emphasis mine); what solutions exist for this case? – Shepmaster Jul 31 '16 at 00:25