ark::concurrency::ThreadPool

Defined in header “ark/concurrency/thread_pool.hh”.


A basic thread pool, which allows you to schedule concrete work items (functions) over some number of threads.

Typedefs

  • using FunctionPtr = std::function< void()>
    The signature of a work item.

Methods

  • ThreadPool(const std::string & name, size_t thread_count)
    Constructor. Defines the number of threads you’d like the pool to run with.

  • ThreadPool(const ThreadPoolConfig & config)
    Constructor. Configures the thread-pool with the given configuration.

  • ~ThreadPool()
    Destructor. Halts all worker threads (if not halted already) and cleans up resources. Any unscheduled work is lost.

  • ThreadPool(const ThreadPool & other)
    Prevent copying/moving this structure.

  • ThreadPool(ThreadPool && other)

  • ThreadPool & operator=(const ThreadPool & other)

  • ThreadPool & operator=(ThreadPool && other)

  • void wait()
    Waits for all currently queued work to be completed before returning.

  • bool wait_for(std::chrono::nanoseconds duration)
    Waits for all currently queued work to be completed before returning, or for the specified timeout to be hit. Returns true if the thread pool is idle when this routine returns, or false otherwise.

  • size_t work_items()
    Returns the number of active items (in queue and being worked on). This number may be invalid by the time you read it.

  • bool idle()
    Returns true if the pool is idle, false otherwise.

  • void stop()
    Halts all worker threads. All unscheduled work will remain unscheduled. This is automatically invoked in the destructor.

  • void clear_queue()
    Clears all queued data. Active work will continue to execute until it is complete, and then the pool should enter an ‘idle’ state.

  • void schedule(const FunctionPtr & function)
    Schedules work to be executed by the thread pool.

  • std::vector< std::string > active_functions()
    Returns all actively-executing work. Note that this is just captured as an instant in time; it might be invalidated by the time you inspect the contents.

  • ThreadPoolStatistics statistics()
    Returns statistics related to this pool, useful for debugging.