Parallel.For quirk can leave your code running sequentially

I have been experimenting with the Task Parallel Library December CTP in preparation for a talk at work, and in the process I came across a really weird feature that turns out to have a completely mundane solution. As it will likely catch others out too, I’ve decided to write a blog entry about it.

If you try taking the following C# code:

and convert it to use the new parallel for loop:

and run it on a computer with four cores, you might expect an output such as:

You will however be very disappointed with the result if you do, as the whole loop actually runs on one thread in a sequential fashion. It turns out that the reason for this is simple practicalities of getting this stuff working at a basic level for the CTP. As I discovered on the MSDN parallel forum, the reason is that the Parallel.For method breaks the loop up into groups of eight iterations and assigns each group of eight to the next available thread. So if your loop is of eight or less iterations, then it will run sequentially. You can test this by simply adjusting the for loop to 0 .. 15 say and it will use two threads if you have two cores etc.

Has Adobe just killed SWX?

adobe.pngAdobe today announced a new open source initiative called BlazeDS, which sees the previously proprietary AMF protocol file format made open source. Why is this a big deal? Well up until now, Flash-based RIA developers wanting to pass data between the client and a back-end server have had to choose between three unappealing technologies: XML/JSON, Adobe’s official remoting technologies and unofficial third party tools based on “hacking” Adobe file formats. The first suffers from serialization/ deserialization and verbose data format overheads. The second is just plain expensive (and only works with Java back-ends). The third is of dubious legality. BlazeDS changes all of that.

BlazeDS is based on the AMF file format used in Flash Remoting, and in the (until today) dubious legality of products like AMFPHP. With the release of BlazeDS and the transformation of AMF into an open file format, Adobe have made AMFPHP legal, which is superb news for RIA developers. Its worth thanking Microsoft here therefore. Why? Well ask yourself why, other than through a fear of Silverlight stealing the RIA market from Flash, would Adobe be given away a previously valuable asset?

And so back to the subject of this post. Has Adobe just killed SWX? Until today, SWX lacked (as far as I could tell) the ability to pass complex objects back and forth between server and client, but it more than made up for this by the server providing the data as native SWF files. However now that AMFPHP is fully legal and SWX remains in the legal grey zone, to me the choice between AMFPHP and SWX becomes a no-brainer. I can see no reason now to use SWX.

I invited Aral Balkan to respond to this post. He didn’t disappoint and provided a very detailed response on his blog.

Governments and IT just do not mix

el_reg.pngLast Friday, the British Government announced a joint marketing strategy with industry that is intended to promote British expertise in IT. Trade & Investment Minister Lord Digby Jones stated that the strategy “is a catalyst to stimulate discussion amongst Government and business about how we sell the UK ICT sector to the world.”

But there is a problem. A press release that accompanied the announcement carries a website that promises more information on the strategy. However Her Majesty’s Government forgot to register the domain for the site, much less put any content on it. Never fear though, the dmain is now registered … by The Register!

Read the full story here.

See the website in question (www.ictmarketingstrategy.co.uk) here.

Amazon lose another patent battle.

amazon.pngBack in October, I reported on Amazon’s defeat by a Lord of the Rings actor. Well it looks like a bad year on the patent front for Amazon as the European Patent Office has overturned another patent within Europe. This time it was the trusty FFII who successfully challenged Amazon. The patent was “a method in a computer system for co-ordinating delivery of a gift from a gift giver to a recipient, the gift and recipient being specified in a gift order”.

Read the (now defunct) patent claim here.

Read the FFII press release here.