From 25f2c97eb909c48b96384c7cff7f7f36be8ca509 Mon Sep 17 00:00:00 2001 From: Sai Kishor Kothakota Date: Mon, 1 Jul 2024 19:45:11 +0200 Subject: [PATCH] Add resources_lock_ lock_guards to avoid race condition when loading robot_description through topic (#1451) --- hardware_interface/src/resource_manager.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hardware_interface/src/resource_manager.cpp b/hardware_interface/src/resource_manager.cpp index 7be0cd0cb6..207fbf102d 100644 --- a/hardware_interface/src/resource_manager.cpp +++ b/hardware_interface/src/resource_manager.cpp @@ -1012,6 +1012,7 @@ bool ResourceManager::load_and_initialize_components( const std::string sensor_type = "sensor"; const std::string actuator_type = "actuator"; + std::lock_guard resource_guard(resources_lock_); for (const auto & individual_hardware_info : hardware_info) { // Check for identical names @@ -1597,6 +1598,7 @@ return_type ResourceManager::set_component_state( return false; }; + std::lock_guard guard(resources_lock_); bool found = find_set_component_state( std::bind(&ResourceStorage::set_component_state, resource_storage_.get(), _1, _2), resource_storage_->actuators_);