Skip to content

Add implementation of spin_some for MultiThreadedExecutor #85

Closed

Description

@jackieokay

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.

Activity

  1. self-assigned this
    on Aug 13, 2015
  2. jackieokay commented on Sep 11, 2015

    @jackieokay
    ContributorAuthor

    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:

    1. Check if there is available work (non-blocking)
    2. Do the available work.
    3. 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.

    Also, it needs a test.

  3. added
    in progressActively being worked on (Kanban column)
    and removed
    readyWork is about to start (Kanban column)
    on Sep 11, 2015
  4. added
    readyWork is about to start (Kanban column)
    and removed
    in progressActively being worked on (Kanban column)
    readyWork is about to start (Kanban column)
    on Sep 15, 2015
  5. jackieokay commented on Nov 11, 2015

    @jackieokay
    ContributorAuthor

    there should also be multi-threaded implementations of spin_once and `spin_until_future_complete...

    I'm pulling this out of the backlog because of my current work on abstracting synchronization in rclcpp.

  6. added
    in progressActively being worked on (Kanban column)
    and removed
    readyWork is about to start (Kanban column)
    on Nov 11, 2015
  7. removed
    in progressActively being worked on (Kanban column)
    on Nov 17, 2015
  8. added a commit that references this issue on Feb 22, 2022
  9. added a commit that references this issue on Jul 9, 2022
  10. clalancette commented on Jan 19, 2024

    @clalancette
    Contributor

    This was done ages ago, so closing this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions