vspline 1.1.0
Generic C++11 Code for Uniform B-Splines
Classes | Namespaces | Variables
thread_pool.h File Reference

provides a thread pool for vspline's multithread() routine More...

#include <thread>
#include <mutex>
#include <queue>
#include <functional>
#include <condition_variable>

Go to the source code of this file.

Classes

class  vspline_threadpool::thread_pool
 

Namespaces

namespace  vspline_threadpool
 

Variables

const int vspline_threadpool::ncores = std::thread::hardware_concurrency()
 number of CPU cores in the system More...
 
const int vspline_threadpool::default_njobs = 2 * ncores
 when multithreading, use this number of jobs per default. This looks like overkill and unnecessary signalling overhead, but it improves performance over just having as many threads as there are physical cores. Why is this so? There are several possibilities I've considered: More...
 

Detailed Description

provides a thread pool for vspline's multithread() routine

class thread_pool aims to provide a simple and straightforward implementation of a thread pool for multithread() in multithread.h, but the class might find use elsewhere. The operation is simple, I think of it as 'piranha mode' ;)

a set of worker threads is launched which wait for 'tasks', which come in the shape of std::function<void()>, from a queue. When woken, a worker thread tries to obtain a task. If it succeeds, the task is executed, and the worker thread tries to get another task. If none is to be had, it goes to sleep, waiting to be woken once there are new tasks.

Definition in file thread_pool.h.