diff --git a/libcxx/src/thread.cpp b/libcxx/src/thread.cpp index 406e71d2ac64..467402b6b423 100644 --- a/libcxx/src/thread.cpp +++ b/libcxx/src/thread.cpp @@ -46,14 +46,17 @@ thread::~thread() void thread::join() { - int ec = __libcpp_thread_join(&__t_); + int ec = EINVAL; + if (__t_ != 0) + { + ec = __libcpp_thread_join(&__t_); + if (ec == 0) + __t_ = 0; + } #ifndef _LIBCPP_NO_EXCEPTIONS if (ec) throw system_error(error_code(ec, system_category()), "thread::join failed"); -#else - (void)ec; #endif // _LIBCPP_NO_EXCEPTIONS - __t_ = 0; } void