Gavin Pugh - A Videogame Programming Blog

Month: November, 2010

XNA/C# – Thread-local storage on Xbox 360

29 November, 2010 at 9:48am | XNA / C#

Thread-local storage

 

I initially begun writing this particular article back in April. Back then with XNA 3.1 to play with, there was actually a method of ‘thread-local storage’ for Xbox. With the release of XNA 4.0, this last remaining native method was removed. The [ThreadLocal] attribute though was added to the Compact Framework, but it seems to be a stubbed non-functional attribute on Xbox 360.

So, where does that leave us? There is various ways you can manually code up a thread-local storage solution. The whole crux of it is data-retrieval and storage on a per-thread basis. The most immediately obvious way to go is just some sort of associative container, a Dictionary<> of some sort of thread ‘id’ mapped to the data you wish to store.

Read more »

XNA/C# – [ThreadStatic] attribute is broken on Xbox 360

26 November, 2010 at 8:34pm | XNA / C#

[ThreadStatic]

Continuing on from my last XNA post, I had a go at using [ThreadStatic] on the Xbox. Specifically this attribute was not available with XNA 3.1, but was introduced in the new 4.0 version.

At first glace it worked fine, I threw in the same code I’d used on Windows. Unlike under 3.1 it compiles without issue. However, the attribute appears to actually do nothing it all. It behaves just like the attribute wasn’t there, just like a regular plain static variable.

I found this issue from attempting to use [ThreadStatic] within some code I had written for a future article here. The code was to profile various methods of implementing Thread-local storage on the Xbox 360. Switching the code to add a test case for [ThreadStatic] worked fine at first, but I was seeing very odd profile numbers coming back from it. On closer inspection in the debugger I could see that the TLS values weren’t thread-specific, they were getting written to at runtime by other executing threads.

Read more »

XNA/C# – Changes in the Xbox 360 Compact Framework

23 November, 2010 at 10:03am | XNA / C#

Compact Framework

A few months back I was partway through an article about XNA. I was going to cover how to implement efficient “Thread Local Storage” on the Xbox 360. Back in Game Studio v3.1 I found that the [ThreadStatic] attribute was not supported on the Xbox, and the only workable methods out of the box were the Thread.GetData(), Thread.SetData() methods. Those methods aren’t good performance-wise, so I proceeded to look at more efficient alternatives.

That article was going to detail the solution I came up with, and currently used in my engine. However upon revisiting the work recently and upgrading to the new v4.0 XNA, I found that I had some compile errors. Specifically ‘System.Threading.LocalDataStoreSlot’ was now missing, it’s that slow method of TLS I was using to benchmark against. So I commented that code out. I then figured why not for the hell of it try to enable the [ThreadStatic] code, that I had #ifdef’d to the WINDOWS build. Lo and behold, it now compiled on Xbox 360!

Read more »

New domain, new game, new book…

18 November, 2010 at 10:05am | Life, My Games, New Games, Work

Music To Make Games By... Is No More.

Well, my posting on here has hit a bit of a lull. Overwork isn’t my excuse this time, since my last post things have been pretty crunch-free at my day job.

I think I’ve just chilled out a little more at home, not so much coding. Been actually playing games a lot more than usual; enjoying “Fallout: New Vegas” right now, and played a ton of “Dead Rising 2” as well. To hark back to an old blog post I made here about Dead Rising; I can confidently say that Blue Castle Games did a great job on it, you guys do indeed rock!

Recently I did just move my blog to a new domain. I felt the old website name “Music To Make Games By…”, and it’s really long domain name wasn’t to my liking. The original aim for my blog was to talk a lot about the Guitar Hero games I’m working on. That sort of thing is pretty difficult to do though. For obvious reasons I can’t talk about games that aren’t announced yet. Also, to talk about anything with any sort of meaty ‘behind the scenes’ content I’d need to run it by Neversoft first. So yeah, all that fell by the wayside and I mainly ended up covering my foray into XNA and C#; with a few distractions on the way.

Read more »