From 740d7cdd71fc2f068e44bfc6c8cc7e9565de16f6 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 19 Jul 2012 14:42:36 +0300 Subject: [PATCH] Fix a race condition --- source/internaltask.cpp | 9 +++++---- source/internaltask.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/source/internaltask.cpp b/source/internaltask.cpp index c117bad..bcea591 100644 --- a/source/internaltask.cpp +++ b/source/internaltask.cpp @@ -17,15 +17,16 @@ void InternalTask::start() Task::Status InternalTask::check() { - if(worker->get_status()!=RUNNING) - signal_finished.emit(worker->get_status()==SUCCESS); - return worker->get_status(); + Status result = worker->get_status(); + if(result!=RUNNING) + signal_finished.emit(result==SUCCESS); + return result; } Task::Status InternalTask::wait() { Status result; - while((result = worker->get_status())==RUNNING) ; + while((result = check())==RUNNING) ; return result; } diff --git a/source/internaltask.h b/source/internaltask.h index 399e119..c927b0b 100644 --- a/source/internaltask.h +++ b/source/internaltask.h @@ -17,7 +17,7 @@ public: friend class InternalTask; protected: - Status status; + volatile Status status; Worker(); -- 2.45.2