1

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.

Jimmy J
  • 1,953
  • 1
  • 14
  • 20
  • How many threads do you have? How many processors? Are you setting affinity for several threads, or just one? – Michael Burr Apr 18 '09 at 07:36
  • I have two CPUs, I'm only setting affinity for one thread. The other threads aren't even running at the moment. – Jimmy J Apr 18 '09 at 08:27
  • 2
    Please don't erase the original question. People might be having the same problem. – Thomas Jul 07 '10 at 01:33

3 Answers3

1

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
  • 295,962
  • 43
  • 465
  • 541
  • I assume it would return an error if I didn't have rights. Besides which, SetProcessAffinityMask() works perfectly... – Jimmy J Apr 18 '09 at 07:02
1

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
  • 45,913
  • 27
  • 138
  • 182
1

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

binarybob
  • 3,529
  • 3
  • 23
  • 21