c++ - How to start a thread on another core without setting processor affinity to a specific core? -


how start std::thread on core without explicitly setting processor affinity specific core?

i aware thread can assigned specific core there way tell scheduler start process on core , let scheduler decide core best run process on?

the short answer don't.

you have 2 choices:

  1. you choose processor core(s) thread can run on, setting affinity.
  2. you let scheduler choose core(s) thread run on.

either choose, or scheduler chooses. simple that.

for seem want (start threads run on multiple cores) want let scheduler scheduling.

setting processor affinity cases know enough scheduling of threads can better job of scheduling general purpose scheduler can. @ least i've seen, 75% of time people set affinity, it's mistake, , end slowing code down. 24% no harm, no real good. and, perhaps as 1% of time, accomplish useful.

rest assured people write schedulers aware if spin dozen threads, wasn't intent run on single core. simplest (and common) case schedule threads on available cores. when doesn't, it's because user has (at least indirectly) configured system not (e.g., part of power management on laptop may when it's running on battery, limits number of cores in use, @ least under circumstances).


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -