From 2435c99ad7bf17312e9457692ff0b66332386e2f Mon Sep 17 00:00:00 2001 From: Yuri Gorshenin Date: Mon, 16 Mar 2015 14:55:02 +0300 Subject: [PATCH] [threads] Not explicitly joined threads are detached in dtor. --- base/thread.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/base/thread.cpp b/base/thread.cpp index a70462c3b2..f63d0ca068 100644 --- a/base/thread.cpp +++ b/base/thread.cpp @@ -34,7 +34,16 @@ void RunRoutine(IRoutine * routine) // Thread wrapper implementation Thread::Thread() : m_routine(0) {} -Thread::~Thread() { Join(); } +Thread::~Thread() +{ + // @todo (ygorshenin@): in general, it's not a good practice to + // implicitly detach thread since detached threads work in + // background, consume system resources and make it hard to reason + // about program. Thus, all places where Thread is instantiated + // should be fixed to explicitly detach thread. + if (m_thread.joinable()) + m_thread.detach(); +} bool Thread::Create(IRoutine * pRoutine) {