Skip to content

Commit 25f2c97

Browse files
authored
Add resources_lock_ lock_guards to avoid race condition when loading robot_description through topic (#1451)
1 parent 03adeba commit 25f2c97

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

hardware_interface/src/resource_manager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,7 @@ bool ResourceManager::load_and_initialize_components(
10121012
const std::string sensor_type = "sensor";
10131013
const std::string actuator_type = "actuator";
10141014

1015+
std::lock_guard<std::recursive_mutex> resource_guard(resources_lock_);
10151016
for (const auto & individual_hardware_info : hardware_info)
10161017
{
10171018
// Check for identical names
@@ -1597,6 +1598,7 @@ return_type ResourceManager::set_component_state(
15971598
return false;
15981599
};
15991600

1601+
std::lock_guard<std::recursive_mutex> guard(resources_lock_);
16001602
bool found = find_set_component_state(
16011603
std::bind(&ResourceStorage::set_component_state<Actuator>, resource_storage_.get(), _1, _2),
16021604
resource_storage_->actuators_);

0 commit comments

Comments
 (0)