Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong place to insert the lock? #1959

Closed
yashi opened this issue Dec 19, 2024 · 6 comments
Closed

Wrong place to insert the lock? #1959

yashi opened this issue Dec 19, 2024 · 6 comments

Comments

@yashi
Copy link
Contributor

yashi commented Dec 19, 2024

The PR #1599 which backports #1451 failed to insert the lock in the right place.

const auto hardware_info = hardware_interface::parse_control_resources_from_urdf(urdf);
if (load_and_initialize_components)
std::lock_guard<std::recursive_mutex> resource_guard(resources_lock_);
{
for (const auto & individual_hardware_info : hardware_info)

This means that when load_and_initialize_components is true the lock is taken, but the rest of the block will be executed regardless.
Or, is it intended fix?

@destogl Please confirm.

@yashi yashi changed the title Wrong place to insert the lock Wrong place to insert the lock? Dec 19, 2024
@christophfroehlich
Copy link
Contributor

@saikishor ?

@saikishor
Copy link
Member

This means that when load_and_initialize_components is true the lock is taken, but the rest of the block will be executed regardless.
Or, is it intended fix?

You are totally right!

@yashi
Copy link
Contributor Author

yashi commented Dec 19, 2024

@saikishor Just curious, what exactly are you protecting with resources_lock_? I mean, what does resource in the name of the lock refering to? At first I thought read_write_status.failed_hardware_names but it's not only this but others as well?

@saikishor
Copy link
Member

Hello!

For Humble, we are trying to protect the read and write methods to access the object before it is constructed completely or configured.

HardwareReadWriteStatus ResourceManager::read(
const rclcpp::Time & time, const rclcpp::Duration & period)
{
std::lock_guard<std::recursive_mutex> guard(resources_lock_);
read_write_status.ok = true;
read_write_status.failed_hardware_names.clear();
auto read_components = [&](auto & components)
{
for (auto & component : components)
{
if (component.read(time, period) != return_type::OK)
{
read_write_status.ok = false;
read_write_status.failed_hardware_names.push_back(component.get_name());
resource_storage_->remove_all_hardware_interfaces_from_available_list(component.get_name());
}
}
};
read_components(resource_storage_->actuators_);
read_components(resource_storage_->sensors_);
read_components(resource_storage_->systems_);
return read_write_status;
}
// CM API: Called in "update"-thread
HardwareReadWriteStatus ResourceManager::write(
const rclcpp::Time & time, const rclcpp::Duration & period)
{
std::lock_guard<std::recursive_mutex> guard(resources_lock_);
read_write_status.ok = true;
read_write_status.failed_hardware_names.clear();
auto write_components = [&](auto & components)
{
for (auto & component : components)
{
if (component.write(time, period) != return_type::OK)
{
read_write_status.ok = false;
read_write_status.failed_hardware_names.push_back(component.get_name());
resource_storage_->remove_all_hardware_interfaces_from_available_list(component.get_name());
}
}
};

That is the reason, we would need this mutex here. For rolling on, it might not be needed as it is handled individually in each component

@christophfroehlich
Copy link
Contributor

fixed with #1960

@saikishor
Copy link
Member

The fix in #1960 is merged. I will go ahead and close this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants