@@ -103,7 +103,11 @@ export namespace CppUtils::UnitTest::Thread::Scheduler
103103 suite.addTest("Order of execution", [&] {
104104 auto scheduler = CppUtils::Thread::Scheduler{};
105105 auto executionOrder = std::vector<std::size_t>{};
106- auto record = [&](std::size_t value) { executionOrder.push_back(value); };
106+ auto mutex = std::mutex{};
107+ auto record = [&](std::size_t value) {
108+ auto lock = std::unique_lock{mutex};
109+ executionOrder.push_back(value);
110+ };
107111
108112 scheduler.schedule([&] { record(1); }, 100ms);
109113 scheduler.schedule([&] { record(2); }, 50ms);
@@ -121,8 +125,12 @@ export namespace CppUtils::UnitTest::Thread::Scheduler
121125 using TimePoint = CppUtils::Thread::Scheduler::TimePoint;
122126 auto scheduler = CppUtils::Thread::Scheduler{};
123127 auto times = std::vector<TimePoint>{};
128+ auto mutex = std::mutex{};
124129
125- auto record = [&](TimePoint timePoint) { times.push_back(timePoint); };
130+ auto record = [&](TimePoint timePoint) {
131+ auto lock = std::unique_lock{mutex};
132+ times.push_back(timePoint);
133+ };
126134
127135 scheduler.schedule([&] { record(Clock::now()); }, 100ms);
128136 scheduler.schedule([&] { record(Clock::now()); }, 250ms);
@@ -141,8 +149,12 @@ export namespace CppUtils::UnitTest::Thread::Scheduler
141149 using TimePoint = CppUtils::Thread::Scheduler::TimePoint;
142150 auto scheduler = CppUtils::Thread::Scheduler{200ms};
143151 auto times = std::vector<TimePoint>{};
152+ auto mutex = std::mutex{};
144153
145- auto record = [&](TimePoint timePoint) { times.push_back(timePoint); };
154+ auto record = [&](TimePoint timePoint) {
155+ auto lock = std::unique_lock{mutex};
156+ times.push_back(timePoint);
157+ };
146158
147159 scheduler.schedule([&] { record(Clock::now()); }, 100ms);
148160 scheduler.schedule([&] { record(Clock::now()); }, 250ms);
@@ -159,7 +171,11 @@ export namespace CppUtils::UnitTest::Thread::Scheduler
159171 suite.addTest("Schedule events in reverse order", [&] {
160172 auto scheduler = CppUtils::Thread::Scheduler{};
161173 auto executionOrder = std::vector<std::size_t>{};
162- auto record = [&](std::size_t value) { executionOrder.push_back(value); };
174+ auto mutex = std::mutex{};
175+ auto record = [&](std::size_t value) {
176+ auto lock = std::unique_lock{mutex};
177+ executionOrder.push_back(value);
178+ };
163179
164180 scheduler.schedule([&] { record(2); }, 200ms);
165181 scheduler.schedule([&] { record(1); }, 100ms);
0 commit comments