You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add implementation of spin_some for MultiThreadedExecutor #85
Currently spin_some has a single-threaded implementation in Executor that gets inherited by the child classes. The implementation for the MultiThreadedExecutor should try assign the tasks to different threads.
This relates to the upcoming discussion about the rcl API: how should we define the "spin" functions in Executor?
spin: Blocking call, do work indefinitely as it comes in.
spin_once: Do one "cycle" of work, with optional timeout. In a single-threaded executor, this means executing the first available executable. In a multi-threaded executor, does this mean executing exactly one executable, or does it mean executing one executable per thread? Does blocking mean that all threads block until they have work to do, or
spin_some: Do all the work that is immediately available to the executor. This is probably the most ill-defined of the spin functions. The current single-threaded implementation is:
Check if there is available work (non-blocking)
Do the available work.
Repeat until there is no more available work.
A few ideas for spin_some for MultiThreadedExecutor:
Atomically check all of the work that is immediately available without blocking. Then, assign the executables to each available thread. If # of executables is less than # of threads, some threads might not do any work. If # of executables is greater than # of threads, each thread receives a fair amount of executables and executes them concurrently with the other threads.
This does not allow for new work to come in while work is being done, so it is not consistent with the single-threaded implementation.
Naively launch N threads (where N is the hardware concurrency) where each thread runs the single-threaded spin_some. The get_next_executable call is protected with a mutex, the execute_any_executable call is not.
The problem with this implementation is if new work comes in after threads have joined, then the new work cannot be assigned to these joined threads.
Each spin function should have a spin_node equivalent, and vice versa.
The MultiThreadedExecutor probably should be modified to have a thread pool rather than spawning and joining threads at the beginning and end of each spin call.
Activity
jackieokay commentedon Sep 11, 2015
This relates to the upcoming discussion about the rcl API: how should we define the "spin" functions in Executor?
spin: Blocking call, do work indefinitely as it comes in.spin_once: Do one "cycle" of work, with optional timeout. In a single-threaded executor, this means executing the first available executable. In a multi-threaded executor, does this mean executing exactly one executable, or does it mean executing one executable per thread? Does blocking mean that all threads block until they have work to do, orspin_some: Do all the work that is immediately available to the executor. This is probably the most ill-defined of the spin functions. The current single-threaded implementation is:A few ideas for
spin_someforMultiThreadedExecutor:This does not allow for new work to come in while work is being done, so it is not consistent with the single-threaded implementation.
spin_some. Theget_next_executablecall is protected with a mutex, theexecute_any_executablecall is not.The problem with this implementation is if new work comes in after threads have joined, then the new work cannot be assigned to these joined threads.
Each
spinfunction should have aspin_nodeequivalent, and vice versa.The
MultiThreadedExecutorprobably should be modified to have a thread pool rather than spawning and joining threads at the beginning and end of eachspincall.Also, it needs a test.
jackieokay commentedon Nov 11, 2015
there should also be multi-threaded implementations of
spin_onceand `spin_until_future_complete...I'm pulling this out of the backlog because of my current work on abstracting synchronization in rclcpp.
Merge pull request ros2#85 from mauropasse/mauro/add-rmw-listener-api…
Zero init topic names and types (ros2#85)
Introduce rosbag2_transport layer and CLI (ros2#38)
clalancette commentedon Jan 19, 2024
This was done ages ago, so closing this out.