Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
nix::ThreadPool Class Reference

#include <thread-pool.hh>

Public Types

using work_t = boost::compat::move_only_function<void()>

Public Member Functions

 ThreadPool (size_t maxThreads=0)
void enqueue (work_t t)
void process ()
void shutdown ()

Detailed Description

A simple thread pool that executes a queue of work items (lambdas).

Member Typedef Documentation

◆ work_t

using nix::ThreadPool::work_t = boost::compat::move_only_function<void()>

An individual work item.

Move-only, so that a work item can own what it operates on. std::move_only_function would do, but libc++ does not implement it yet.

Member Function Documentation

◆ enqueue()

void nix::ThreadPool::enqueue ( work_t t)

Enqueue a function to be executed by the thread pool.

◆ process()

void nix::ThreadPool::process ( )

Execute work items until the queue is empty.

Note
Note that work items are allowed to add new items to the queue; this is handled correctly.

Queue processing stops prematurely if any work item throws an exception. This exception is propagated to the calling thread. If multiple work items throw an exception concurrently, only one item is propagated; the others are printed on stderr and otherwise ignored.

◆ shutdown()

void nix::ThreadPool::shutdown ( )

Shut down all worker threads and wait until they've exited. Active work items are finished, but any pending work items are discarded.


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