From 93b8a9aeb361d007175397667120b2ce86cfd805 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Sat, 28 Jul 2018 23:48:03 +0200 Subject: [PATCH] Cannot use range-based for loop when container is modified. --- src/plugins/host_load.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/plugins/host_load.cpp b/src/plugins/host_load.cpp index 4a549d8efe..ad42f71b6f 100644 --- a/src/plugins/host_load.cpp +++ b/src/plugins/host_load.cpp @@ -85,9 +85,12 @@ void HostLoad::update() double now = surf_get_clock(); // This loop updates the flops that the host executed for the ongoing computations - for (auto& pair : current_activities) { - auto& activity = pair.first; // Just an alias - auto& remaining_cost_after_last_update = pair.second; // Just an alias + auto iter = begin(current_activities); + while (iter != end(current_activities)) { + auto& activity = iter->first; // Just an alias + auto& remaining_cost_after_last_update = iter->second; // Just an alias + auto current_iter = iter; + ++iter; if (activity->surf_action_->get_finish_time() != now && activity->state_ == e_smx_state_t::SIMIX_RUNNING) { if (remaining_cost_after_last_update == activity_uninitialized_remaining_cost) { @@ -99,7 +102,7 @@ void HostLoad::update() } else if (activity->state_ == e_smx_state_t::SIMIX_DONE) { computed_flops_ += remaining_cost_after_last_update; - current_activities.erase(activity); + current_activities.erase(current_iter); } } -- 2.20.1