I am sure that kernel affinity is not included in std :: thread. It is assumed that the OS is perfectly capable of making the best use of existing kernels. In all but the most extreme cases, you are not going to beat the OS solution, so the assumption is fair.
If you go this route, you need to add some kind of solution to your code in order to take into account the architecture of the machine, so that your solution is better than the OS on every computer that you run on. It takes a lot of effort! First you need to limit the number of threads according to the number of cores on the computer. And you do not know what else is going on in the car; OS is working!
This is why thread pools exist. By default, they have as many threads as there are kernels automatically configured by the language runtime. AFAIK C ++ 11 does not have one of them. Thus, one good thing you can do to get optimal performance is to find out how many cores there are and to limit the number of threads that you have on this number. Otherwise, it might be best to trust the OS.
Joachim Pileborg's comment is noteworthy unless the work performed by each thread outweighs the I / O overhead.
source share