From: Martin Quinson Date: Mon, 20 Nov 2023 13:43:08 +0000 (+0100) Subject: Fix a bug in concurrent modif of a collection that was revealed by GLIBCXX_DEBUG X-Git-Tag: v3.35~13 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/201605b6315d5474e458c655eb4fb9952151b732 Fix a bug in concurrent modif of a collection that was revealed by GLIBCXX_DEBUG Thanks agiersch for the diagnostic and patch. I tested it effective. --- diff --git a/src/plugins/battery.cpp b/src/plugins/battery.cpp index 9639bf67e5..c682e178ac 100644 --- a/src/plugins/battery.cpp +++ b/src/plugins/battery.cpp @@ -208,18 +208,16 @@ void Battery::update() energy_stored_j_ = std::min(energy_stored_j_, 3600 * capacity_wh_); last_updated_ = now; - std::vector> 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); }); }