   Best way to force single core affinity in Win32?
  So, for C win32, what is the best way to force the affinity to a single core?Will this work?DWORD dwProcessAffinityMask, dwSysAffinityMask, dwFirstProcessorMask = 1;GetProcessAffinityMask(GetCurrentProcess(), &dwProcessAffinityMask, &dwSysAffinityMask);while(!(dwFirstProcessorMask & dwSysAffinityMask))dwFirstProcessorMask=1;SetThreadAffinityMask(GetCurrentThread(), dwFirstProcessorMask);   
  By not doing it? That looks naively right to me, but that sort of thing reeks of a hacky work-around.   ;  It's not going to work if the first bit of dwSysAffinityMask is not set, it'll just loop forever. You want something like:DWORD dwProcessAffinityMask, dwSystemAffinityMask;GetProcessAffinityMask(GetCurrentProcess(), &dwProcessAffinityMask, &dwSystemAffinityMask);if (dwSystemAffinityMask == 0) {  // error, this can happen on Windows 2008/Windows 7 with more than 64 CPUs}dwProcessAffinityMask = 1;while ((dwProcessAffinityMask & dwSystemAffinityMask) == 0) {  dwProcessAffinityMask <<= 1;}SetThreadAffinityMask(GetCurrentThread(), dwProcessAffinityMask);But as Telastyn says, the vast majority of applications should not need (and would not want) to do this.   ;  You can't "force" a thread to execute only on a given CPU core; affinities are a suggestion, not a demand.In any case it is considered poor practice to muck around with thread affinities, because doing so can lead to undesirable situations like priority inversion. The use of thread affinities usually indicates a poor design decision somewhere.   ;Quote:Original post by ApochPiQYou can't "force" a thread to execute only on a given CPU core; affinities are a suggestion, not a demand.In any case it is considered poor practice to muck around with thread affinities, because doing so can lead to undesirable situations like priority inversion. The use of thread affinities usually indicates a poor design decision somewhere.Well to be fair, the documentation for QueryPerformanceCounter still (indirectly) suggests using it to avoid issues with multiple processors.;Quote:Original post by MJPQuote:Original post by ApochPiQYou can't "force" a thread to execute only on a given CPU core; affinities are a suggestion, not a demand.In any case it is considered poor practice to muck around with thread affinities, because doing so can lead to undesirable situations like priority inversion. The use of thread affinities usually indicates a poor design decision somewhere.Well to be fair, the documentation for QueryPerformanceCounter still (indirectly) suggests using it to avoid issues with multiple processors.That's why I was asking.Thanks everyone for the various replies.   