Search code examples
c++multithreadingwindows-7windows-10affinity

Does a processor affinity set by SetThreadAffinityMask also apply to children threads?


I have an application that makes use of many threads, one of them being more time critical than the others. I have already tried using priority, but have found that Windows doesn't always honor the priority to the extent I would like and sometimes allows lessor priority threads to block my critical thread for long periods (50+ milliseconds). To resolve this, I'm thinking of setting a processor affinity for each thread to limit the non-critical ones such that they can't use some cores (say cores #1 and #2) and the critical thread will always have those cores (#1 and #2) available.

My question is, if I set a processor affinity mask to my entry-point thread via SetThreadAffinityMask(), do subsequent threads created by this initial thread inherit the affinity mask? Or do I need to manually set the affinity each and every time I spawn a thread throughout the system?


Solution

  • I can confirm the thread affinity is NOT inherited when creating a thread using std::thread with VS2015 on Windows 10.