@@ -178,7 +178,10 @@ TEST_F(TestClockWakeup, no_wakeup_on_sim_time) {
178
178
TEST_F (TestClockWakeup, multiple_threads_wait_on_one_clock) {
179
179
auto clock = std::make_shared<rclcpp::Clock>(RCL_ROS_TIME);
180
180
181
- std::vector<bool > thread_finished (10 , false );
181
+ std::vector<std::atomic_bool> thread_finished (10 );
182
+ for (std::atomic_bool & finished : thread_finished) {
183
+ finished = false ;
184
+ }
182
185
183
186
std::vector<std::thread> threads;
184
187
@@ -196,7 +199,7 @@ TEST_F(TestClockWakeup, multiple_threads_wait_on_one_clock) {
196
199
// wait a bit so all threads can execute the sleep_until
197
200
std::this_thread::sleep_for (std::chrono::milliseconds (500 ));
198
201
199
- for (const bool & finished : thread_finished) {
202
+ for (const std::atomic_bool & finished : thread_finished) {
200
203
EXPECT_FALSE (finished);
201
204
}
202
205
@@ -207,7 +210,7 @@ TEST_F(TestClockWakeup, multiple_threads_wait_on_one_clock) {
207
210
bool threads_finished = false ;
208
211
while (!threads_finished && start_time + std::chrono::seconds (1 ) > cur_time) {
209
212
threads_finished = true ;
210
- for (const bool finished : thread_finished) {
213
+ for (const std::atomic_bool & finished : thread_finished) {
211
214
if (!finished) {
212
215
threads_finished = false ;
213
216
}
@@ -217,7 +220,7 @@ TEST_F(TestClockWakeup, multiple_threads_wait_on_one_clock) {
217
220
cur_time = std::chrono::steady_clock::now ();
218
221
}
219
222
220
- for (const bool finished : thread_finished) {
223
+ for (const std::atomic_bool & finished : thread_finished) {
221
224
EXPECT_TRUE (finished);
222
225
}
223
226
0 commit comments