ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
2

Are callbacks of the same Node called sequentally in MultiThreadExecutor?

asked 2019-02-23 21:56:33 -0500

Teckel gravatar image

updated 2019-02-23 22:00:35 -0500

Let's suppose I have nodes A, B and C on a MultiThreadExecutor with two threads.

Then suppose that the Event Queue has the following events: Node A Callback1 | Node A Callback1 | Node B Callback 2

From what I understand:

  1. The first thread takes the Node A Callback1.
  2. Then the second thread takes the next Node A Callback1.

This will mean that callbacks on the same Node should be thread safe when using MultiThreadExecutor, is that true? Is there a way to guarantee that the callbacks of the same node are executed sequentially or that each node has its own thread?

Thank you

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
5

answered 2019-03-04 11:32:07 -0500

jacobperron gravatar image

This will mean that callbacks on the same Node should be thread safe when using MultiThreadExecutor, is that true?

Your understanding is correct.

Is there a way to guarantee that the callbacks of the same node are executed sequentially or that each node has its own thread?

This is what callback groups are for. Adding a node to a MutuallyExclusiveCallbackGroup (rclpy) (MutuallyExclusive callback type (rclcpp)), will ensure that its callbacks are executed sequentially.

edit flag offensive delete link more

Comments

Thank you. You have pointed me in the right direction. Now I am sure that I should correct some mistakes on my project.

Teckel gravatar image Teckel  ( 2019-03-04 12:09:33 -0500 )edit
0

answered 2019-07-29 06:48:13 -0500

scg gravatar image

Each Node has it's own default callbackgroup, which is in fact MutuallyExclusive.

That means by default each callback on the same Node will not be executed in parallel with other callbacks on that same Node and thus they don't have to be thread-safe.

edit flag offensive delete link more

Question Tools

4 followers

Stats

Asked: 2019-02-23 21:56:33 -0500

Seen: 688 times

Last updated: Jul 29 '19