Search code examples
c++multithreadingpooling

Best OS portable thread pool library


I'm developing a program in C++ for both POSIX-compatible systems and Windows(R) and was wondering:

  1. What is the best OS portable thread pool library? Or should I make my own?
  2. Is there any point of pooling more treads than there are physical processor cores?

Solution

    1. The new C++11 standard has threading support, so if your compiler supports that, you should prefer it. Otherwise, there is Boost.Thread. Those aren't thread pool libraries, but you can build a thread pool on top of them.
    2. Depends on what problem you try to solve. If you want to run n tasks in parallel, you have to start n threads, no matter how many processor cores you have (multithreading was popular before processors grew multiple cores, and normally hundreds of threads are already running in parallel, so a few more don't matter that much). On the other hand, thread creation is expensive, so you shouldn't create a new thread for each short-lived background thread. In C++11, you can use futures for such background tasks.