diff options
author | Tor Brede Vekterli <vekterli@oath.com> | 2019-01-15 09:48:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-15 09:48:44 +0100 |
commit | 959655d2bd9f743b34c6e5caac21e44de48187e3 (patch) | |
tree | 4aba819ffb380484fedf12770fb5b7e8bddc5a04 /fastos | |
parent | 86b4be8b2439880c7e40c157896e1b42caac4b86 (diff) | |
parent | 7d1dda33a7b4e1e1727947c0104ed86036a5bef4 (diff) |
Merge pull request #8109 from vespa-engine/vekterli/fix-tsan-detected-data-races
Fix some ThreadSanitizer reported data races
Diffstat (limited to 'fastos')
-rw-r--r-- | fastos/src/vespa/fastos/thread.cpp | 4 | ||||
-rw-r--r-- | fastos/src/vespa/fastos/thread.h | 5 |
2 files changed, 5 insertions, 4 deletions
diff --git a/fastos/src/vespa/fastos/thread.cpp b/fastos/src/vespa/fastos/thread.cpp index 5e3400b70e3..3df8fa584a7 100644 --- a/fastos/src/vespa/fastos/thread.cpp +++ b/fastos/src/vespa/fastos/thread.cpp @@ -266,7 +266,7 @@ void FastOS_ThreadInterface::Hook () } _owner = nullptr; _startArg = nullptr; - _breakFlag = false; + _breakFlag.store(false, std::memory_order_relaxed); finished = _pool->isClosed(); dispatchedGuard.unlock(); // END lock @@ -322,7 +322,7 @@ void FastOS_ThreadInterface::Dispatch(FastOS_Runnable *newOwner, void *arg) void FastOS_ThreadInterface::SetBreakFlag() { std::lock_guard<std::mutex> dispatchedGuard(_dispatchedMutex); - _breakFlag = true; + _breakFlag.store(true, std::memory_order_relaxed); _dispatchedCond.notify_one(); } diff --git a/fastos/src/vespa/fastos/thread.h b/fastos/src/vespa/fastos/thread.h index 2726efe3cf0..c025a48d563 100644 --- a/fastos/src/vespa/fastos/thread.h +++ b/fastos/src/vespa/fastos/thread.h @@ -12,6 +12,7 @@ #include "types.h" +#include <atomic> #include <mutex> #include <condition_variable> @@ -294,7 +295,7 @@ protected: /** * Break flag. If true, the thread should exit. */ - bool _breakFlag; + std::atomic<bool> _breakFlag; /** * Is this thread active or free in the threadpool? @@ -385,7 +386,7 @@ public: */ bool GetBreakFlag () const { - return _breakFlag; + return _breakFlag.load(std::memory_order_relaxed); } /** |