Poco

class ActiveThreadPool

Library: Foundation
Package: Threading
Header: Poco/ActiveThreadPool.h

Description

A thread pool manages and recycles individual Poco::Thread objects to help reduce thread creation costs in programs that use threads.

The thread pool supports a task queue. When there are no idle threads, tasks are placed in the task queue to wait for execution. Use case for this pool is running many (more than os-max-thread-count) short live tasks

Member Summary

Member Functions: capacity, defaultPool, expiryTimeout, getStackSize, joinAll, name, setExpiryTimeout, start

Constructors

ActiveThreadPool

ActiveThreadPool(
    int capacity = static_cast < int > (Environment::processorCount ())+ 1,
    int stackSize = 0
);

Creates a thread pool with a maximum thread count of capacity. Threads are created with given stack size.

ActiveThreadPool

ActiveThreadPool(
    const std::string & name,
    int capacity = static_cast < int > (Environment::processorCount ())+ 1,
    int stackSize = 0
);

Creates a thread pool with the given name and a maximum thread count of capacity. Threads are created with given stack size.

Destructor

~ActiveThreadPool

~ActiveThreadPool();

Currently running threads will remain active until they complete.

Member Functions

capacity

int capacity() const;

Returns the capacity of threads.

defaultPool static

static ActiveThreadPool & defaultPool();

Returns a reference to the default thread pool.

expiryTimeout

int expiryTimeout() const;

Returns the thread expiry timeout value in milliseconds. The default expiryTimeout is 30000 milliseconds (30 seconds).

getStackSize

int getStackSize() const;

Returns the stack size used to create new threads.

joinAll

void joinAll();

Waits for all threads to exit and removes all threads from the thread pool.

name

const std::string & name() const;

Returns the name of the thread pool, or an empty string if no name has been specified in the constructor.

setExpiryTimeout

void setExpiryTimeout(
    int expiryTimeout
);

Set the thread expiry timeout value in milliseconds. The default expiryTimeout is 30000 milliseconds (30 seconds).

start

void start(
    Runnable & target,
    int priority = 0
);

Obtains a thread and starts the target.