Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/DefaultTimer.cpp

Issue 29402565: Issue 5082 - fix possible race condition in DefaultTimer (Closed)
Patch Set: Created April 4, 2017, 10:50 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/DefaultTimer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/DefaultTimer.cpp
diff --git a/src/DefaultTimer.cpp b/src/DefaultTimer.cpp
index aeb00ccf18e026827eb0564aac4987751e3df420..597dec3effc0abc41fc9dc81dd473558287c799a 100644
--- a/src/DefaultTimer.cpp
+++ b/src/DefaultTimer.cpp
@@ -30,7 +30,10 @@ DefaultTimer::DefaultTimer()
DefaultTimer::~DefaultTimer()
{
- shouldThreadStop = true;
+ {
+ std::lock_guard<std::mutex> lock(mutex);
+ shouldThreadStop = true;
+ }
conditionVariable.notify_one();
if (m_thread.joinable())
m_thread.join();
@@ -48,7 +51,7 @@ void DefaultTimer::SetTimer(const std::chrono::milliseconds& timeout, const Time
void DefaultTimer::ThreadFunc()
{
- while (!shouldThreadStop)
+ while (true)
{
std::unique_lock<std::mutex> lock(mutex);
if (timers.empty())
@@ -79,5 +82,7 @@ void DefaultTimer::ThreadFunc()
}
lock.lock();
}
+ if (shouldThreadStop)
+ return;
}
}
« no previous file with comments | « src/DefaultTimer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld