SetThreadAffinityMask is ignored....any ideas?

2.8k Views Asked by At

Update: I found the problem - embarrassingly/ironically enough it was was calling SetThreadAffinity() in the wrong thread, not the main one (program startup is messy...)

It's all working now, thanks for all the help! I've given everybody an upvote for taking part in my little debug session.

3

There are 3 best solutions below

1
On

Does calling it like this make any difference?:

DWORD_PTR mask = 1; 
SetThreadAffinityMask(GetCurrentThread(), mask);

Does your thread handle have the necessary access rights?:

Windows Server 2003 and Windows XP/2000: The handle must have the THREAD_SET_INFORMATION and THREAD_QUERY_INFORMATION access rights.

1
On

I haven't had any problems with that function though it has been a couple of months since I used them.

Here are some things you might want to check:

  • Do not have conflicting SetProcessAffinityMask and SetThreadAffinityMask
  • If you have one thread on processor 2, then the rest of the program could be using processor 1
  • Display GetCurrentProcessorNumber to test if its running on the right CPU.
0
On

What you're doing seems correct, could you perhaps try SetThreadIdealProcessor instead?