Closed jrmadsen closed 2 years ago
ThreadPool::Config
ThreadPool
pthread_setschedprio
Threading::SetPinAffinity(<cpu-id>)
Threading::SetThreadPriority(<cpu-id>)
Threading::SetThreadPriority(<cpu-id>, Threading::NativeThread&)
Threading::GetNumberOfPhysicalCpus()
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 };
Overview
ThreadPool::Config
classThreadPool
constructorpthread_setschedprio
Threading::SetPinAffinity(<cpu-id>)
overload which applies to current threadThreading::SetThreadPriority(<cpu-id>)
overloadThreading::SetThreadPriority(<cpu-id>, Threading::NativeThread&)
overloadThreading::GetNumberOfPhysicalCpus()
Example
ThreadPool::Config