Medium
Sizing a thread pool inside a container
This service runs in a Docker container started with a CPU quota limiting it to 2 cores' worth of CPU time (e.g. docker run --cpus=2 ...), on a host machine with 64 physical cores. It sizes its thread pool directly off std::thread::hardware_concurrency() at startup, as shown. What does hardware_concurrency() actually report here, and what goes wrong for the thread pool as a result?
pool_init.cpp
#include <thread>
#include <cstdio>
int main() {
unsigned n = std::thread::hardware_concurrency();
printf("sizing thread pool with %u threads\n", n);
// ThreadPool pool(n); // naive: one worker thread per reported core
}45 of 53 in Operating Systems