From 5bb023de734ede0a80a01e866126c2eb28180a2f Mon Sep 17 00:00:00 2001 From: chenkeyu Date: Tue, 6 Aug 2024 12:06:50 +0800 Subject: [PATCH] use atomic to avoid data race of switch_ Issue:https://gitee.com/openharmony/commonlibrary_c_utils/issues/IAI4FU?from=project-issue Signed-off-by: chenkeyu --- base/src/event_reactor.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/base/src/event_reactor.h b/base/src/event_reactor.h index 83139bd..5ebd548 100644 --- a/base/src/event_reactor.h +++ b/base/src/event_reactor.h @@ -16,6 +16,7 @@ #ifndef UTILS_EVENT_REACTOR_H #define UTILS_EVENT_REACTOR_H +#include #include #include #include @@ -69,7 +70,7 @@ public: private: mutable volatile bool loopReady_; // refers to whether reactor is ready to call RunLoop(). - volatile bool switch_; // a switch to enable while-loop in RunLoop(). true: start, false: stop. + std::atomic switch_; // a switch to enable while-loop in RunLoop(). true: start, false: stop. std::unique_ptr demultiplexer_; std::recursive_mutex mutex_; std::list> timerEventHandlers_; -- Gitee