Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do threads get handled? [closed]

Am I getting it right, that if you have for example four CPU's and four threads, these are getting distributed on each CPU? And when you have got five threads, one CPU has to handle two threads at once?

Thanks in advance :)


1 Answers

The only guarantee you get is that the threads will run independently of each other. Scheduling is done by the operating system and the OS usually tries to make all cores busy, but since there is a lot more running on your computer than just your program, there's no guarantee that your four threads will always run on the four cores.

On Windows, you can pin threads to a processor core, but this is neither standard nor cross-platform, and not always to the benefit of your program.

like image 132
zneak Avatar answered Sep 22 '26 06:09

zneak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!