LLVM  14.0.0git
Public Member Functions | List of all members
llvm::ThreadPool Class Reference

A ThreadPool for asynchronous parallel execution on a defined number of threads. More...

#include "llvm/Support/ThreadPool.h"

Public Member Functions

 ThreadPool (ThreadPoolStrategy S=hardware_concurrency())
 Construct a pool using the hardware strategy S for mapping hardware execution resources (threads, cores, CPUs) Defaults to using the maximum execution resources in the system, but accounting for the affinity mask. More...
 
 ~ThreadPool ()
 Blocking destructor: the pool will wait for all the threads to complete. More...
 
template<typename Function , typename... Args>
auto async (Function &&F, Args &&...ArgList)
 Asynchronous submission of a task to the pool. More...
 
template<typename Func >
auto async (Func &&F) -> std::shared_future< decltype(F())>
 Asynchronous submission of a task to the pool. More...
 
void wait ()
 Blocking wait for all the threads to complete and the queue to be empty. More...
 
unsigned getThreadCount () const
 
bool isWorkerThread () const
 Returns true if the current thread is a worker thread of this thread pool. More...
 

Detailed Description

A ThreadPool for asynchronous parallel execution on a defined number of threads.

The pool keeps a vector of threads alive, waiting on a condition variable for some work to become available.

Definition at line 37 of file ThreadPool.h.

Constructor & Destructor Documentation

◆ ThreadPool()

ThreadPool::ThreadPool ( ThreadPoolStrategy  S = hardware_concurrency())

Construct a pool using the hardware strategy S for mapping hardware execution resources (threads, cores, CPUs) Defaults to using the maximum execution resources in the system, but accounting for the affinity mask.

Definition at line 23 of file ThreadPool.cpp.

References function, move, and S.

◆ ~ThreadPool()

ThreadPool::~ThreadPool ( )

Blocking destructor: the pool will wait for all the threads to complete.

Definition at line 84 of file ThreadPool.cpp.

Member Function Documentation

◆ async() [1/2]

template<typename Func >
auto llvm::ThreadPool::async ( Func &&  F) -> std::shared_future<decltype(F())>
inline

Asynchronous submission of a task to the pool.

The returned future can be used to wait for the task to finish and is non-blocking on destruction.

Definition at line 60 of file ThreadPool.h.

References F, and function.

◆ async() [2/2]

template<typename Function , typename... Args>
auto llvm::ThreadPool::async ( Function &&  F,
Args &&...  ArgList 
)
inline

Asynchronous submission of a task to the pool.

The returned future can be used to wait for the task to finish and is non-blocking on destruction.

Definition at line 51 of file ThreadPool.h.

References F, and move.

Referenced by llvm::TaskQueue::async(), llvm::DWARFLinker::link(), llvm::ThinLTOCodeGenerator::run(), llvm::splitCodeGen(), and splitCodeGen().

◆ getThreadCount()

unsigned llvm::ThreadPool::getThreadCount ( ) const
inline

Definition at line 68 of file ThreadPool.h.

◆ isWorkerThread()

bool ThreadPool::isWorkerThread ( ) const

Returns true if the current thread is a worker thread of this thread pool.

Definition at line 75 of file ThreadPool.cpp.

References llvm::this_thread::get_id(), and Thread.

◆ wait()

void ThreadPool::wait ( )

Blocking wait for all the threads to complete and the queue to be empty.

It is an error to try to add new tasks while blocking on this call.

Definition at line 69 of file ThreadPool.cpp.

Referenced by llvm::DWARFLinker::link(), splitCodeGen(), and llvm::TaskQueue::~TaskQueue().


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