From f260b13a6fe6a228283f48d98533619e8bd5f1dc Mon Sep 17 00:00:00 2001 From: grundman Date: Fri, 16 Oct 2015 11:19:27 -0700 Subject: [PATCH] Fix racy modification of ForThread::m_state during invocation of stop() --- modules/core/src/parallel_pthreads.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/core/src/parallel_pthreads.cpp b/modules/core/src/parallel_pthreads.cpp index df99f18bf2..8bf131e144 100644 --- a/modules/core/src/parallel_pthreads.cpp +++ b/modules/core/src/parallel_pthreads.cpp @@ -304,14 +304,18 @@ void ForThread::stop() { if(m_state == eFTStarted) { + pthread_mutex_lock(&m_thread_mutex); m_state = eFTToStop; + pthread_mutex_unlock(&m_thread_mutex); run(); pthread_join(m_posix_thread, NULL); } + pthread_mutex_lock(&m_thread_mutex); m_state = eFTStoped; + pthread_mutex_unlock(&m_thread_mutex); } void ForThread::run()