ThreadPool Class Reference

The ThreadPool class. More...

#include <ArmarXCore/core/services/tasks/ThreadPool.h>

Classes

class  Handle
 
struct  Impl
 

Public Member Functions

int getAvailableTaskCount () const
 If queing is disabled, returns the number of available threads.
 
Handle runTask (std::function< void()> task)
 Adds a task to the thread pool if a thread is currently available.
 
 ThreadPool (std::size_t pool_size, bool queueTasks=false)
 Constructor.
 
 ~ThreadPool ()
 Destructor.
 

Detailed Description

The ThreadPool class.

Usage:

ThreadPool pool(5);
auto handle = pool.runTask([]{
...
});
handle.join();
// or handle.detach();
ThreadPool(std::size_t pool_size, bool queueTasks=false)
Constructor.

Definition at line 45 of file ThreadPool.h.

Constructor & Destructor Documentation

◆ ThreadPool()

ThreadPool ( std::size_t pool_size,
bool queueTasks = false )

Constructor.

Definition at line 56 of file ThreadPool.cpp.

◆ ~ThreadPool()

~ThreadPool ( )

Destructor.

Definition at line 66 of file ThreadPool.cpp.

Member Function Documentation

◆ getAvailableTaskCount()

int getAvailableTaskCount ( ) const

If queing is disabled, returns the number of available threads.

Otherwise returns -1;

Definition at line 109 of file ThreadPool.cpp.

◆ runTask()

ThreadPool::Handle runTask ( std::function< void()> task)

Adds a task to the thread pool if a thread is currently available.

Returns
returns true if a thread is available, otherwise returns false.

Definition at line 82 of file ThreadPool.cpp.


The documentation for this class was generated from the following files: