LLVM  6.0.0svn
Public Types | 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 Types

using TaskTy = std::function< void()>
 
using PackagedTaskTy = std::packaged_task< void()>
 

Public Member Functions

 ThreadPool ()
 Construct a pool with the number of threads found by hardware_concurrency(). More...
 
 ThreadPool (unsigned ThreadCount)
 Construct a pool of ThreadCount threads. More...
 
 ~ThreadPool ()
 Blocking destructor: the pool will wait for all the threads to complete. More...
 
template<typename Function , typename... Args>
std::shared_future< void > async (Function &&F, Args &&... ArgList)
 Asynchronous submission of a task to the pool. More...
 
template<typename Function >
std::shared_future< void > async (Function &&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...
 

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 36 of file ThreadPool.h.

Member Typedef Documentation

◆ PackagedTaskTy

using llvm::ThreadPool::PackagedTaskTy = std::packaged_task<void()>

Definition at line 39 of file ThreadPool.h.

◆ TaskTy

Definition at line 38 of file ThreadPool.h.

Constructor & Destructor Documentation

◆ ThreadPool() [1/2]

ThreadPool::ThreadPool ( )

Construct a pool with the number of threads found by hardware_concurrency().

Definition at line 25 of file ThreadPool.cpp.

Referenced by ~ThreadPool().

◆ ThreadPool() [2/2]

ThreadPool::ThreadPool ( unsigned  ThreadCount)

Construct a pool of ThreadCount threads.

Definition at line 27 of file ThreadPool.cpp.

◆ ~ThreadPool()

ThreadPool::~ThreadPool ( )

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

Definition at line 100 of file ThreadPool.cpp.

References llvm::errs(), ThreadPool(), and wait().

Member Function Documentation

◆ async() [1/2]

template<typename Function , typename... Args>
std::shared_future<void> 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 54 of file ThreadPool.h.

References F().

Referenced by llvm::lto::Config::addSaveTemps(), llvm::ThinLTOCodeGenerator::run(), and llvm::lto::ThinBackendProc::~ThinBackendProc().

◆ async() [2/2]

template<typename Function >
std::shared_future<void> llvm::ThreadPool::async ( Function &&  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 63 of file ThreadPool.h.

References F(), and wait().

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

References assert().

Referenced by llvm::lto::Config::addSaveTemps(), async(), llvm::lto::ThinBackendProc::~ThinBackendProc(), and ~ThreadPool().


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