Nix 2.93.3
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
nix::ThreadPool Class Reference

#include <thread-pool.hh>

Public Types

typedef std::function< void(AsyncIoRoot &)> work_t

Public Member Functions

 ThreadPool (const char *name, size_t maxThreads=0)
void enqueueWithAio (const work_t &t)
void enqueue (std::function< void()> t)
void process ()
kj::Promise< Result< void > > processAsync ()

Detailed Description

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

Member Typedef Documentation

◆ work_t

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

An individual work item.

Todo
use std::packaged_task?

Member Function Documentation

◆ enqueueWithAio()

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

◆ processAsync()

kj::Promise< Result< void > > nix::ThreadPool::processAsync ( )

Like process, but async.


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