Effect of sched_setaffinity() on new threads [duplicate]

  affinity, c++, linux, multithreading

Does sched_setaffinity(), when called from a "main" process, affect the running core on which new threads are created from this running process?

From what I see, all the threads that are created after calling sched_setaffinity() are always created on the same core that the "main" process was set to run on. Is this something I can rely on to happen every time the program is executed?

In the following pseudo-code, is it guaranteed that threadA, threadB and threadC will always be running on the same core?

int main()
{
   sched_setaffinity(...);
   threadA = std::thread();
   threadB = std::thread();
   threadC = std::thread();
}

Source: Windows Questions C++

LEAVE A COMMENT