vitrio 0.1.4
High-throughput image I/O for Cryo-Electron Microscopy (CryoEM)
Loading...
Searching...
No Matches
Public Member Functions | List of all members
vitrio::thread_pool_executor Class Referencefinal

An executor backed by a fixed pool of worker threads. More...

#include <vitrio/concurrency/thread_pool_executor.hpp>

Inheritance diagram for vitrio::thread_pool_executor:
Inheritance graph
[legend]
Collaboration diagram for vitrio::thread_pool_executor:
Collaboration graph
[legend]

Public Member Functions

 thread_pool_executor (std::size_t worker_count)
 Construct a pool with a given number of worker threads.
 
 thread_pool_executor (const thread_pool_executor &other)=delete
 
 thread_pool_executor (thread_pool_executor &&other)=delete
 
thread_pool_executor & operator= (const thread_pool_executor &other)=delete
 
thread_pool_executor & operator= (thread_pool_executor &&other)=delete
 
std::size_t get_worker_count () const noexcept
 Get the number of worker threads.
 
void submit (std::unique_ptr< task > t, std::shared_ptr< completion_notifier > notifier) override
 Queue a unit of work for a worker to run.
 
- Public Member Functions inherited from vitrio::executor
 executor (const executor &other)=default
 
 executor (executor &&other)=default
 
executor & operator= (const executor &other)=default
 
executor & operator= (executor &&other)=default
 

Detailed Description

An executor backed by a fixed pool of worker threads.

Every worker pulls the next submitted task from one shared queue, runs it, and reports its outcome to the notifier it was submitted with, catching whatever the task threw. Submitting never blocks the caller and never runs the task itself; a task queued while every worker is busy simply waits its turn. The queue is unbounded.

The worker count should track the concurrency the destination the tasks read from or write to actually supports, not the number of CPU cores: a worker mostly blocks in I/O rather than computing.

The destructor waits for every already-queued task to run before returning, submitted or not yet started.

Thread safety
submit may be called concurrently.

Constructor & Destructor Documentation

◆ thread_pool_executor()

vitrio::thread_pool_executor::thread_pool_executor ( std::size_t  worker_count)
explicit

Construct a pool with a given number of worker threads.

Parameters
worker_countThreads to spawn. Must be greater than zero.
Exceptions
std::invalid_argumentIf worker_count is zero.

Member Function Documentation

◆ get_worker_count()

std::size_t vitrio::thread_pool_executor::get_worker_count ( ) const
noexcept

Get the number of worker threads.

Returns
std::size_t The worker count passed at construction.

◆ submit()

void vitrio::thread_pool_executor::submit ( std::unique_ptr< task >  t,
std::shared_ptr< completion_notifier >  notifier 
)
overridevirtual

Queue a unit of work for a worker to run.

Parameters
tThe work to run. Must not be null.
notifierWhere the outcome is reported. Must not be null.
Exceptions
std::invalid_argumentIf t or notifier is null.

Implements vitrio::executor.


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