You really answered your questions!
A key feature of code that burns a lot of CPUs is that it never does anything that blocks (for example, waiting for network or file I / O) and never voluntarily gives its time fragment (for example, sleep (), etc. .) ,.
Another trick is that the code should do something that the compiler cannot optimize. Thus, most likely, your write code on the CPU outputs something based on the calculation of the cycle at the end, or simply compiles without optimization, so the optimizer is not tempted to delete the unnecessary cycle. Since you are trying to load the processor, there is no point optimizing anyway.
As you suggested, the single-threaded code corresponding to this description will saturate the CPU core, if the OS has more such processes than it has kernels to start them, then it will cyclically plan them, and the use of each of them will form part 100%.
source share