Halide
ThreadPool.h File Reference
#include <condition_variable>
#include <future>
#include <mutex>
#include <queue>
#include <thread>
#include <utility>
#include <unistd.h>

Go to the source code of this file.

Classes

class  Halide::Internal::ThreadPool< T >
 

Namespaces

 Halide
 This file defines the class FunctionDAG, which is our representation of a Halide pipeline, and contains methods to using Halide's bounds tools to query properties of it.
 
 Halide::Internal
 

Detailed Description

Define a simple thread pool utility that is modeled on the api of C++11 std::async(); since implementation details of std::async can vary considerably, with no control over thread spawning, this class allows us to use the same model but with precise control over thread usage.

A ThreadPool is created with a specific number of threads, which will never vary over the life of the ThreadPool. (If created without a specific number of threads, it will attempt to use threads == number-of-cores.)

Each async request will go into a queue, and will be serviced by the next available thread from the pool.

The ThreadPool's dtor will block until all currently-executing tasks to finish (but won't schedule any more).

Note that this is a fairly simpleminded ThreadPool, meant for tasks that are fairly coarse (e.g. different tasks in a test); it is specifically not intended to be the underlying implementation for Halide runtime threads

Definition in file ThreadPool.h.