Xbox360 Threads, just interested ...

I know that the xbox has multi cores and can run several threads concurrently, how do you write for a particular core on the xbox 360, or will the CLR choose when to use another core. Or maybe our code will only run on 1, can someone please enlighten me. Hopefully, it will be as easy as this -

Thread myThread =newThread(newThreadStart(myProc));
myThread.SetApartmentState(
ApartmentState.MTA)
myThread.Start();

and the clr does all the hard work. I am just interested thats all ...

Dave

[943 byte] By [LotusExigeS1] at [2007-12-26]
# 1
I was reading up on this yesterday and I thought it was very interesting. Intel has an arcticle on it:

http://www3.intel.com/cd/ids/developer/asmo-na/eng/221160.htm?page=1

You don't want to write for a particular core since if your game will work on windows you never know how many cores will be available.

vidalsasoon at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 2
In general, it's the job of the OS scheduler to spread threads across

cores. If multiple cores are available, and multiple threads are

running, an efficient scheduler will not bounce the threads between the

cores, because that would cause cache thrashing.

If you KNOW

that certain threads will work better when bound to certain cores, you

use the ::SetThreadAffinity() Win32 call, which is available as

Thread.SetProcessorAffinity() in .NET.

Note that the "apartment state" is not necessary to set; the default is what you want.

JonWatte at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 3

Thanks guys !

Thread.SetProcessorAffinity(), looks like this doesnt exist in XNA :O(

LotusExigeS1 at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 4
Right now how threading will work on the xbox really hasn't been documented at all by the MS folks. We've asked for such a doc...
TheZMan at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 5
The Xbox thread scheduler is significantly different to the one in the Windows kernel.

On Windows, the OS does all sorts of smart stuff to load balance

between different threads and processes, so the usual advice is just to

kick off however many threads you need and let the OS figure out the

details.

On Xbox things are more manual. This can be both a good thing and a bad

thing: a good thing because you get more control and therefore more

deterministic performance, but a bad thing because you have to think a

bit more carefully about what you are doing. If you just create threads

and let them run in the default way, they will all execute on the same

CPU core, which is unlikely to be what you really wanted! To balance

threads across cores, you need to call

Thread.CurrentThread.SetProcessorAffinity. I seem to remember this has

to be called by the thread you want to change, ie. you can't alter the

affinity of some other thread, so typically this call will be the first

thing you do after creating the new thread.

I'm not sure exactly how many hardware threads will be available for

you to play with (I didn't work on that area of the code). I know we

reserved either one or two for framework use, leaving either four or

five for your own code, but don't remember which. Regardless, you

generally want to be thinking in terms of running three threads at

once: trying to use more than that can get you in trouble unless you

really understand what you are doing, since the hardware has three

independent CPU cores.

ShawnHargreaves-MSFT at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 6

Thread.CurrentThread.SetProcessorAffinity

will this be available in the release version because I cant find it in beta 2 ? Unless I am being thick !

LotusExigeS1 at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 7
This API is not available on Windows, but it's there in beta2 if you create an Xbox project.
ShawnHargreaves-MSFT at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...