multithreading – Why do n + 1 worker threads need to be created in multithreaded applications?

Question:

Where n is the number of physical cores. I have come across this rule more than once, but I just cannot understand why to do this and whether it is always more efficient than creating n threads.

Answer:

but I just can't understand why to do this

As a rule, "general-purpose" programs, in addition to the actual calculations, perform input-output operations (disk, network, other devices). It would be nice to load the kernel with useful work while waiting for slow operations. Therefore, +1 added. Why +1 and not more? Now I can't find it – but I remember exactly, I saw the benchmarks for make -jN . The +1 combination won almost everywhere. Thus, the established practice has a purely experimental reasoning.

and is it always more efficient than creating n threads

Not always. If the processes are busy exclusively with recalculations, and the share of I / O operations is negligible, adding an "additional" stream will not add the total speed. Moreover, the speed may drop slightly.

Scroll to Top