Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Cannot use range-based for loop when container is modified.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 28 Jul 2018 21:48:03 +0000 (23:48 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 28 Jul 2018 22:16:18 +0000 (00:16 +0200)
src/plugins/host_load.cpp

index 4a549d8..ad42f71 100644 (file)
@@ -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
   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) {
 
     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;
     }
     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);
     }
   }
 
     }
   }