Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
2  
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
add comment

1 Answer

up vote 3 down vote accepted

SetThreadAffinityMask

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
add comment

Your Answer

 
discard

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.