Exit cleanly from any thread, fixes #17