Writing is hard work: what I’ve been up to recently…

Just a brief note to explain what I’ve been up to recently (and why I’ve got about four fun blog posts which I haven’t had time to write up yet). I’m wildly pleased to say that I’m currently writing a C# book for Manning (the same folks who published Groovy in Action). I can’t give any more details at the moment, but hopefully as we get closer to publication I can give more details about not just the content but the writing process and anything interesting I’ve discovered while writing it. (Heck, there’s never enough room for everything you might want … Continue reading Writing is hard work: what I’ve been up to recently…

Non-volatile reads and Interlocked, and how they interact

Recently (May 2007) there’s been a debate on the microsoft.public.dotnet.framework newsgroup about the memory model, non-volatile variables, the Interlocked class, and how they all interact. Consider the following program: Update! I screwed up the code, making all of the combinations possible accidentally. The new code is now in the post – the first few comments are based on the original code. using System; using System.Threading; class Program { int x; int y; void Run() { ThreadStart increment = IncrementVariables; new Thread(increment).Start(); int a = x; int b = y; Console.WriteLine (“a={0}, b={1}”, a, b); } void IncrementVariables() { Interlocked.Increment(ref y); … Continue reading Non-volatile reads and Interlocked, and how they interact