From 8659b61d462dd64b6278f2d6470832f46821cfd5 Mon Sep 17 00:00:00 2001 From: Felix Domke Date: Mon, 18 May 2009 22:47:43 +0200 Subject: [PATCH] fix 'thread recovery' race with sync() by not abusing m_state. --- lib/base/thread.cpp | 11 +++++------ lib/base/thread.h | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/base/thread.cpp b/lib/base/thread.cpp index 58c4fd72..fa923deb 100644 --- a/lib/base/thread.cpp +++ b/lib/base/thread.cpp @@ -9,12 +9,9 @@ void eThread::thread_completed(void *ptr) eThread *p = (eThread*) ptr; p->m_alive = 0; - /* recover state */ - if (!p->m_state.value()) - { - p->m_state.up(); - ASSERT(p->m_state.value() == 1); - } + /* recover state in case thread was cancelled before calling hasStarted */ + if (!p->m_started) + p->hasStarted(); p->thread_finished(); } @@ -48,6 +45,7 @@ int eThread::runAsync(int prio, int policy) ASSERT(m_state.value() == 0); m_alive = 1; + m_started = 0; /* start thread. */ pthread_attr_t attr; @@ -125,5 +123,6 @@ void eThread::kill(bool sendcancel) void eThread::hasStarted() { ASSERT(!m_state.value()); + m_started = 1; m_state.up(); } diff --git a/lib/base/thread.h b/lib/base/thread.h index 12c5b25c..8ee96594 100644 --- a/lib/base/thread.h +++ b/lib/base/thread.h @@ -59,7 +59,7 @@ private: pthread_t the_thread; static void *wrapper(void *ptr); - int m_alive; + int m_alive, m_started; static void thread_completed(void *p); eSemaphore m_state; -- 2.30.2