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

#include <thread-pool.hh>

Public Types

typedef std::function< void()> work_t
 

Public Member Functions

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

Detailed Description

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

Member Typedef Documentation

◆ work_t

typedef std::function<void()> nix::ThreadPool::work_t

An individual work item.

Todo
use std::packaged_task?

Member Function Documentation

◆ enqueue()

void nix::ThreadPool::enqueue ( const 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.


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