views:

861

answers:

3

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.

+1  A: 

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.

Mitch Wheat
I assume it would return an error if I didn't have rights. Besides which, SetProcessAffinityMask() works perfectly...
Jimmy J
+1  A: 

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.
Unknown
GetCurrentProcessorNumber() isn't available in Windows XP...
Jimmy J
Then I would advise you try it on Vista.
Unknown
+1  A: 

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

porkchop
SetThreadIdealProcessor() gives exactly the same result.
Jimmy J