Export (0) Print
Expand All

Thread Pools in the .NET Compact Framework for Xbox 360

A thread pool is a collection of threads that can be used to perform background tasks, freeing the primary application thread to perform other tasks asynchronously. The .NET Compact Framework for Xbox 360 supports thread pools and portions of the System.Threading.ThreadPool class. Thread pools on the Xbox 360 are slightly different than those on the .NET Framework or .NET Compact Framework.

Xbox 360 Thread Pools

The Xbox 360 CPU has six hardware threads (two on each of three cores), each capable of independently executing a software thread. These hardware threads execute independently, but the two hardware threads executing on a single core do share some resources, such as the vector unit and L1 cache.

The thread pool distributes the threads it creates evenly among four available hardware threads (two are reserved for system use). The thread pool does not attempt to determine the activity level of the processors before assigning threads, nor does it try to load-balance existing threads. Once a thread is assigned to a hardware thread, the thread pool will not assign that thread to a different hardware thread.

Maximum Number of Threads

The default maximum number of threads in an Xbox 360 thread pool is 256. When a new task is queued with ThreadPool.QueueUserWorkItem, the thread pool first tries to assign the task to an available thread in the pool. If all threads in the thread pool are busy performing tasks, the thread pool will create a new thread to handle the task, up to the maximum number of threads set for the pool. If no threads are available and the maximum number of threads have already been created, the tasks is queued until a thread in the pool becomes available.

To specify the maximum number of threads for the pool, use ThreadPool.SetMaxThreads. If the threads in a thread pool do not require much processing time and are cycling their tasks quickly, it may be more efficient to lower the maximum number of threads for the pool (from its default of 256). Doing so reduces the amount of context switching that occurs when a large number of ready threads are being alternately scheduled for execution on the available processors.

Using Threading

Thread pools provide an easy and efficient mechanism of scheduling asynchronous background tasks. To achieve finer control of the number, type, scheduling, and processor affinity of your application's threads, use the System.Threading.Thread class directly. Threads created with the Thread class can be used instead of, or together with, thread pools.

For more information on using threading and thread pools in the .NET Framework, see Threading and How To: Use a Thread Pool.

Bb203914.note(en-US,XNAGameStudio.20).gifNote
The online MSDN .NET Framework documentation has been updated to show the types and members of the System.Threading namespace that are supported on the Xbox 360. Also see Namespaces and Classes Supported by the .NET Compact Framework for Xbox 360 for information on determining all of the types and members supported by the .NET Compact Framework for Xbox 360.

Community Additions

ADD
Show:
© 2014 Microsoft