jrmadsen / PTL

Parallel Tasking Library (PTL) - Lightweight C++11 mutilthreading tasking system featuring thread-pool, task-groups, and lock-free task queue
MIT License
43 stars 13 forks source link

ThreadPool::Config #23

Closed jrmadsen closed 2 years ago

jrmadsen commented 2 years ago

Overview

Example ThreadPool::Config

intmax_t ncores = PTL::Threading::GetNumberOfCores();
auto     _init  = []() { printf("Started thread %i\n", PTL::Threading::GetThreadId()); };
auto     _fini  = []() { printf("Stopped thread %i\n", PTL::Threading::GetThreadId()); };
auto     _pin   = [ncores](intmax_t i) { return i % ncores; };

PTL::ThreadPool::Config _config{};
_config.init         = true;   // initialize during construction
_config.use_tbb      = false;  // disable tbb
_config.use_affinity = true;   // pin the threads to the cpus
_config.verbose      = 3;      // verbosity
_config.priority     = 0;      // set the thread scheduling priority
_config.pool_size    = 4;      // number of threads
_config.set_affinity = _pin;   // functor for deciding which
                               // cpu to pin threads to
_config.initializer = _init;   // execute when thread starts
_config.finalizer   = _fini;   // execute when thread finalizes

PTL::ThreadPool _tp{ _config };