# HG changeset patch # User Alain Mazy # Date 1655219956 -7200 # Node ID eb8ca34039838f8740ce3f43ef1b14823b88667c # Parent 0d61efc6256c32c0f209db03409df5a14e5cb47b fix: lock mutex when accessing state in HeartBeatThread diff -r 0d61efc6256c -r eb8ca3403983 OrthancServer/Sources/LuaScripting.cpp --- a/OrthancServer/Sources/LuaScripting.cpp Mon Jun 13 18:54:49 2022 +0200 +++ b/OrthancServer/Sources/LuaScripting.cpp Tue Jun 14 17:19:16 2022 +0200 @@ -793,12 +793,13 @@ boost::posix_time::ptime next = boost::posix_time::microsec_clock::universal_time() + PERIODICITY; - while (that->state_ != State_Done) + bool shouldStop = false; + + while (!shouldStop) { boost::this_thread::sleep(boost::posix_time::milliseconds(sleepDelay)); - if (that->state_ != State_Done && - boost::posix_time::microsec_clock::universal_time() >= next) + if (boost::posix_time::microsec_clock::universal_time() >= next) { LuaScripting::Lock lock(*that); @@ -810,6 +811,9 @@ next = boost::posix_time::microsec_clock::universal_time() + PERIODICITY; } + + boost::recursive_mutex::scoped_lock lock(that->mutex_); + shouldStop = that->state_ == State_Done; } }