progschj / ThreadPool

A simple C++11 Thread Pool implementation
zlib License
7.63k stars 2.21k forks source link

What will be the appropriate value for a pool size? #82

Closed anuragvohraec closed 3 years ago

anuragvohraec commented 3 years ago

Hi,

Can any one suggest me how to select an appropriate pool_size value ?

ThreadPool pool(pool_size);

WIll it be equivalent to number of CPU cores on the system ? Or can be greater than it too ?

How do you select it? Specifically if code is supposed to run on different systems?

abbaswasim commented 3 years ago

I would do something something like the following?

ThreadPool pool(std::max(1, std::thread::hardware_concurrency() - 1));

anuragvohraec commented 3 years ago

I would do something something like the following?

ThreadPool pool(std::max(1, std::thread::hardware_concurrency() - 1));

Why -1 from concurrent thread supported, any specific reason ?

abbaswasim commented 3 years ago

To leave a thread or more (-2, -3) for other stuff that might be required to run. Of course you don't need to be that nice. If you don't the OS will still make sure other things run of course but that might not be ideal.