raii_thread refactoring