Modify set_exit_on_term

This implementation is not thread-safe and will cause harmful exit,
but at least it will not cause deadlock on exit.