Wouldn't you want to optionally register one or more callbacks that react to kill command. This would route the kill to a seperate (spawned) thread that would know how to cleanup and cleanly kill the main thread. A "last will and testament" thread could upon startup register its own monitor or a timer to kill itself (thread suicide?).
Also, a theme song? https://www.youtube.com/watch?v=Twix375Me4Q