class mrpt::system::WorkerThreadsPool

Overview

A simple thread pool.

Partly based on: https://github.com/progschj/ThreadPool (ZLib license)

#include <mrpt/system/WorkerThreadsPool.h>

class WorkerThreadsPool
{
public:
    // enums

    enum queue_policy_t;

    // construction

    WorkerThreadsPool();

    WorkerThreadsPool(
        std::size_t num_threads,
        queue_policy_t p = POLICY_FIFO
        );

    // methods

    void resize(std::size_t num_threads);
    void clear();

    template <class F, class... Args>
    auto enqueue(F&& f, Args&&... args);

    std::size_t pendingTasks() const;
};

Methods

void clear()

Stops all working jobs.

template <class F, class... Args>
auto enqueue(F&& f, Args&&... args)

Enqueue one new working item, to be executed by threads when any is available.

std::size_t pendingTasks() const

Returns the number of enqueued tasks, currently waiting for a free working thread to process them.