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. More...
 
Handle runTask (std::function< void()> task)
 Adds a task to the thread pool if a thread is currently available. More...
 
 ThreadPool (std::size_t pool_size, bool queueTasks=false)
 Constructor. More...
 
 ~ThreadPool ()
 Destructor. More...
 

Detailed Description

The ThreadPool class.

Usage:

ThreadPool pool(5);
auto handle = pool.runTask([]{
...
});
handle.join();
// or handle.detach();

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 58 of file ThreadPool.cpp.

◆ ~ThreadPool()

~ThreadPool ( )

Destructor.

Definition at line 68 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 106 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 81 of file ThreadPool.cpp.


The documentation for this class was generated from the following files:
armarx::ThreadPool::ThreadPool
ThreadPool(std::size_t pool_size, bool queueTasks=false)
Constructor.
Definition: ThreadPool.cpp:58