Multithreading for the Xbox 360

UPDATE (12/17/2007): My blog has moved. This post is now located at:

When multithreading on the Xbox 360, here are a few things to keep in mind.

Affinity In multithreaded programming, programmers often lack the ability to specify the Processor Affinity of a thread. Even when API calls are available to specify a processor, it is usually ignored. The reason for this is that modern operating systems have many processes running, each with many threads. The operating system zealously manages processor affinity in order to maximum some metric.

But what about the Xbox? The Xbox 360's operating system does not manage processor affinity. All threads run on the same processor as their parent unless otherwise stated. This basically means that you, the programmer, are responsible for managing processor affinity of your threads, and therefore your applications overall performance.

Processors The Xbox 360 has a 3 core processor capable of running 2 hardware threads each. For simplicity sake, think of this as a system with 6 processors. You can set your threads affinity to 4 of the 6 "processors". Each processor is identified by a number, 0 through 5, and processors 0 and 2 are not available for your use.

Now that we have established some basics about multithreading and the Xbox 360, lets look at the single method that makes all of this possible.

SetProcessorAffinity The SetProcessorAffinity method of the Thread class is the only method needed to manage the processor affinity of your games while running on the Xbox 360. In fact, this method is only available for Xbox 360 projects.

This article is part of the GWB Archives. Original Author: Jason Whitehorn

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.