Skip to content

Commit

Permalink
Add resources_lock_ lock_guards to avoid race condition when loading …
Browse files Browse the repository at this point in the history
…robot_description through topic (#1451)
  • Loading branch information
saikishor authored Jul 1, 2024
1 parent 03adeba commit 25f2c97
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions hardware_interface/src/resource_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::recursive_mutex> resource_guard(resources_lock_);
for (const auto & individual_hardware_info : hardware_info)
{
// Check for identical names
Expand Down Expand Up @@ -1597,6 +1598,7 @@ return_type ResourceManager::set_component_state(
return false;
};

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

0 comments on commit 25f2c97

Please sign in to comment.