Reorganize safe_thread