From eda3c1a23a4c12c52462c6da17a5617236cb5053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Wed, 22 Aug 2018 13:34:42 -0400 Subject: [PATCH] scheduled_executor: initialize mutex before thread Fix race condition where the thread might start before the mutex is properly initialized Change-Id: I47c6947873b9e1e7aef576bf7d2ba79cc9ad1e57 Reviewed-by: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> --- src/scheduled_executor.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/scheduled_executor.h b/src/scheduled_executor.h index baa2c38d11..0a5b5a59df 100644 --- a/src/scheduled_executor.h +++ b/src/scheduled_executor.h @@ -127,10 +127,10 @@ private: void reschedule(std::shared_ptr<RepeatedTask>, time_point t, duration dt); std::atomic_bool running_ {true}; - std::map<time_point, std::vector<Job>> jobs_; + std::map<time_point, std::vector<Job>> jobs_ {}; + std::mutex jobLock_ {}; + std::condition_variable cv_ {}; std::thread thread_; - std::mutex jobLock_; - std::condition_variable cv_; }; } -- GitLab