Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix a bug in concurrent modif of a collection that was revealed by GLIBCXX_DEBUG
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Mon, 20 Nov 2023 13:43:08 +0000 (14:43 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Mon, 20 Nov 2023 13:43:16 +0000 (14:43 +0100)
Thanks agiersch for the diagnostic and patch. I tested it effective.

src/plugins/battery.cpp

index 9639bf6..c682e17 100644 (file)
@@ -208,18 +208,16 @@ void Battery::update()
     energy_stored_j_ = std::min(energy_stored_j_, 3600 * capacity_wh_);
     last_updated_    = now;
 
-    std::vector<std::shared_ptr<Handler>> to_delete = {};
-    for (auto handler : handlers_) {
+    auto handlers_2 = handlers_;
+    for (auto handler : handlers_2) {
       if (abs(handler->time_delta_ - time_delta_s) < 0.000000001) {
         handler->callback_();
         if (handler->persistancy_ == Handler::Persistancy::PERSISTANT)
           handler->time_delta_ = -1;
         else
-          to_delete.push_back(handler);
+          delete_handler(handler);
       }
     }
-    for (auto handler : to_delete)
-      delete_handler(handler);
   });
 }