Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to be able to use multiple cores in my XNA game, but it seems that Thread.SetProcessorAffinity() is only usable on xbox. That being said, is there any way to run a small chunk of my code on another core, or failing that, share the load between all cores?

share|improve this question
You should never use this. Leave the .Net runtime to its own devices - it will do a much better job than you can manage :). The only reason it is available on the XBox is because the XBox .Net runtime does not automatically allocate threads to cores. – Jonathan Dickinson Sep 15 '12 at 18:52
up vote 3 down vote accepted


That being said I'm confused by the second part of your question. Windows threads by default are set to run on all processors/cores. The thread affinity mask exists to allow you to specify that it can only run on specific cores.

This is useful in some rare cases where system calls return differently depending on the core/processor that the thread is currently running on such as QueryPerformanceCounter

Edit: After researching XNA's Thread.SetProcesorAfffinity I think you might just be misunderstanding how multiprocessing works in Windows. Most windows applications do not call SetThreadAffinityMask but instead just create threads and let the OS choose what core/processor (remember some machines have more than one processor) to run the thread on. Windows has a complex scheduler that suspends and resumes threads based off of thread priority to allow more threads than there are physical processors or cores. If you want to learn more I recommend reading one of the Windows Internal books or one of the powerpoints floating around on the web that explain Win32 Kernel.

share|improve this answer
Ah, wonderful. I'm always happy when the solution turns out to be easier than I thought it would be. – Fibericon Sep 15 '12 at 17:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.