Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to set thread affinity to a processor core with the boost thread library?

And would it be a good idea to do so if I needed the processor cores running on 100% for a dozen seconds or would I get better performance if I let the system decide how to handle the threads?

What I need is fast execution and I'm worried the system might spend a few seconds before using all the cores, but I haven't found any way of doing this with boost thread.

like image 252
Kesarion Avatar asked Dec 04 '22 13:12

Kesarion


1 Answers

Your operating system's scheduler should take care of this for you on the order of milliseconds, not seconds. The details depend on which OS you're running on, but one common approach is that when the scheduler runs on an idle CPU, it will check to see if it can steal a thread from another CPU that has too many. That quickly balances the threads across all CPUs.

As a general rule, if you need to set CPU affinity, either you have a very specific and unusual use case, or your operating system has a bug.

like image 125
Jamey Sharp Avatar answered Jan 04 '23 23:01

Jamey Sharp