diff --git a/libc/src/__support/threads/linux/thread.cpp b/libc/src/__support/threads/linux/thread.cpp --- a/libc/src/__support/threads/linux/thread.cpp +++ b/libc/src/__support/threads/linux/thread.cpp @@ -343,18 +343,10 @@ uint32_t joinable_state = uint32_t(DetachState::JOINABLE); if (attrib->detach_state.compare_exchange_strong( joinable_state, uint32_t(DetachState::DETACHED))) { - return int(DetachType::SIMPLE); + return 0; } - // If the thread was already detached, then the detach method should not - // be called at all. If the thread is exiting, then we wait for it to exit - // and free up resources. - // TODO: Should we handle this less destructively? Maybe just return EINVAL? - wait(); - - cleanup_thread_resources(attrib); - - return int(DetachType::CLEANUP); + return EINVAL; } void Thread::wait() { diff --git a/libc/src/pthread/pthread_detach.cpp b/libc/src/pthread/pthread_detach.cpp --- a/libc/src/pthread/pthread_detach.cpp +++ b/libc/src/pthread/pthread_detach.cpp @@ -20,8 +20,7 @@ LLVM_LIBC_FUNCTION(int, pthread_detach, (pthread_t th)) { auto *thread = reinterpret_cast(&th); - thread->detach(); - return 0; + return thread->detach(); } } // namespace __llvm_libc