Is there a way to guarantee a struct's drop implementation will get run absent an abort? That is the drop implementation will run assuming the program either exits normally OR exits by panicking (assuming the configuration is to unwind, not immediately abort).
What I'm actually trying to do is make an API that spawns a new thread. That thread will open and turn on a GPIO output. Before the program exits including if it panics it should at a minimum turn off the GPIO output. If this was super mission critical, a hardware/electrical circuit would be the ultimate solution but I want to do as much as I reasonably can in software to guarantee the output is turned off prior to the program exiting.
I can nearly solve this by having the API
- Spawn a new thread
- Put the join handle of the thread in a struct with a drop impl
- The said drop impl signals the thread to stop (if applicable) and joins the thread
- Inside the spawned thread, the GPIO is opened and put in a struct that has a drop impl that turns off the GPIO
The problem is that if the API was called by some thread that is not the main thread, then it is the responsibility of the writer of main to join the thread that calls the API. In case the main thread were to panic, the writer of main would have to write a similar drop impl.

