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

[documentation] Explain when MultiThreadedExecutor is running multiple threads #2454

Open
wants to merge 5 commits into
base: rolling
Choose a base branch
from

Conversation

Cakem1x
Copy link

@Cakem1x Cakem1x commented Mar 19, 2024

This is a tiny PR that adds a class docstring for the MultiThreadedExecutor. It includes a note about which methods support multithreaded execution.

Please let me know if this is not the right way to suggest additions to the documentation.
Also, please double check if the note is actually true or can be improved.

My context:
I have a unit test with two nodes that communicate with each other and I use the MultiThreadedExecutor to spin both of these nodes. One node publishes a TF, the other one regularly waits for that TF.

In the individual test cases, I have been using multi_threaded_executor_.spin_until_future_complete(some_future);. This leads to a flaky test that sometimes succeeds and sometimes fails. The reason for that seems to be that the MultiThreadedExecutor is only using a single thread when spin_until_future_complete is used. The test would fail (timeout) if the work item from node that waits for the TF gets executed first. Waiting for the TF blocks the main thread until timeout, while the other node that should supply that TF will not get executed.

After changing my test setup to use multi_threaded_executor_.spin(); in a separate thread and just do some_future.wait_for(...) in the test cases, everything is working fine.

So, after finding all that out, I thought I could maybe help others by adding a note somewhere. Just skimming through the API docs, that behavior was not clear to me.

Thanks for having a look!

@Cakem1x Cakem1x marked this pull request as ready for review March 19, 2024 09:49
@fujitatomoya
Copy link
Collaborator

@Cakem1x btw, can you also address DCO error?

Cakem1x and others added 5 commits April 5, 2024 16:25
It includes a note about which methods support multithreaded execution.
Signed-off-by: Matthias Holoch <[email protected]>
This reverts commit e751e1f.

Signed-off-by: Matthias Holoch <[email protected]>
Co-authored-by: Tomoya Fujita <[email protected]>
Signed-off-by: Matthias Holoch <[email protected]>
@@ -61,8 +61,12 @@ class MultiThreadedExecutor : public rclcpp::Executor
RCLCPP_PUBLIC
virtual ~MultiThreadedExecutor();

/// Multi-threaded implementation of spin.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multi-thread 😸

Copy link
Collaborator

@alsora alsora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the new documentation is misleading.

/**
* \sa rclcpp::Executor:spin() for more details
* This function will block until work comes in, and try to execute all work with
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct.
This function won't block until works come in, but rather it will block until interrupted.

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

Successfully merging this pull request may close these issues.

4 participants