Skip to content

(draft) add per callback group thread isolation - #3247

Draft
skyegalaxy wants to merge 2 commits into
ros2:rollingfrom
skyegalaxy:skyegalaxy/add-cbg-thread-isolation
Draft

(draft) add per callback group thread isolation#3247
skyegalaxy wants to merge 2 commits into
ros2:rollingfrom
skyegalaxy:skyegalaxy/add-cbg-thread-isolation

Conversation

@skyegalaxy

@skyegalaxy skyegalaxy commented Sep 1, 2026

Copy link
Copy Markdown
Member

Description

This PR adds a new prototype API to the callback group events executor, allowing for individual callback groups to be assigned a dedicated worker thread. That group's events will now be routed to a private per CBG-handle events queue instead of the shared deque, decoupling its latency from the rest of the system load.

Dedicated threads can optionally also be given a thread name, scheduling policy, priority and CPU affinity (linux only)

Example usage:

#include "rclcpp/executors/events_cbg_executor/events_cbg_executor.hpp"
using rclcpp::executors::EventsCBGExecutor;

auto node = std::make_shared<MyCoolNode>();

// Put the latency-critical work in its own mutually-exclusive callback group.
auto control_cbg =
  node->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
// ...create the control timer/subscription with options.callback_group = control_cbg...

EventsCBGExecutor executor(rclcpp::ExecutorOptions(), 4);   // 4 shared pool threads

// Give the control CBG its own thread: SCHED_FIFO prio 80, pinned to CPU 3.
EventsCBGExecutor::DedicatedThreadOptions opts;
opts.name = "control";
opts.scheduling_policy = EventsCBGExecutor::DedicatedThreadOptions::SchedulingPolicy::Fifo;
opts.priority = 80;
opts.cpu_affinity = {3};
// The next line will take the above options and spawn an additional, persistent thread just for control_cbg
executor.set_dedicated_thread_for_callback_group(control_cbg, opts);  // call this BEFORE the group reaches the executor

executor.add_node(node);
executor.spin();

if your platform doesn't offer CPU pinning / affinity / scheduling policy features, callbacks can still be isolated like so, without passing in a ThreadOptions:

executor.set_dedicated_thread_for_callback_group(control_cbg);
executor.add_node(node);
executor.spin();

Fixes # (issue)

Is this user-facing behavior change?

Users will now be able to selectively isolate callback groups to their own dedicated thread, and configure the thread options at the posix level if on linux.

Did you use Generative AI?

claude fable 5

Additional Information

Skyler Medeiros added 2 commits September 1, 2026 09:23
Signed-off-by: Skyler Medeiros <skye@polymathrobotics.com>
Signed-off-by: Skyler Medeiros <skye@polymathrobotics.com>
@skyegalaxy skyegalaxy changed the title (draft) add per callback thread isolation (draft) add per callback group thread isolation Sep 1, 2026
@skyegalaxy
skyegalaxy marked this pull request as draft September 1, 2026 16:32
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.

1 participant