58#include <condition_variable>
87const int ncores = std::thread::hardware_concurrency() ;
106 bool stay_alive = true ;
111 std::vector < std::thread * > pool ;
140 std::unique_lock<std::mutex> task_lock (
task_mutex ) ;
184 std::function < void() > wf
185 = std::bind ( &thread_pool::worker_thread ,
this ) ;
189 for (
int t = 0 ; t < nthreads ; t++ )
190 pool.push_back (
new std::thread ( wf ) ) ;
204 void launch ( std::function <
void() > job )
207 std::lock_guard<std::mutex> lk_task (
task_mutex ) ;
216 void launch ( std::function <
void() > job ,
int njobs )
222 std::lock_guard<std::mutex> lk_task (
task_mutex ) ;
223 for (
int i = 0 ; i < njobs ; i++ )
235 std::lock_guard<std::mutex> task_lock (
task_mutex ) ;
244 for (
auto threadp : pool )
251 for (
auto threadp : pool )
258#ifndef VSPLINE_SINGLETHREAD
266#ifdef VSPLINE_EXTERN_THREAD_POOL
268extern thread_pool common_thread_pool ;
272static thread_pool common_thread_pool ;
void launch(std::function< void() > job, int njobs)
overload of launch invoking the payload on several worker threads
std::queue< std::function< void() > > task_queue
std::condition_variable task_cv
thread_pool(int nthreads=default_njobs)
void launch(std::function< void() > job)
launch simply enqueues a job and calls notify_one. Such a job will run to it's completion and end sil...
const int ncores
number of CPU cores in the system
const int default_njobs
when multithreading, use this number of jobs per default. This looks like overkill and unnecessary si...