Concurrent Collections and TPL–.NET 4.0

TPL in .NET 4.0 is a cool thing when programming modern PCs which have CPUs with more than one core. CPUs with many cores are popular these days because hardware vendors make CPUs with many cores to cater the Moore’s Law. 🙂 Or they might have tired of shrinking the transistor size up to 32nm. There are smaller versions than that..

Task Parallel Library’s (TPL’s) Task.Factory.StatNew( () => {..} is the .NET 4.0’s replacement for the Thread.QueueUserWorkItem() and asynchronous delegates. In this case TPL is more close to the asynchronous delegates and also it is documented that; TPL can leverage the underlying CPU cores more effectively than asynchronous delegates.

But in the documentation TPL considered as a library for the parallel programming.

And we also have Concurrent Collections in System.Collections.Concurrent namespace which contains the thread safe versions of the normal collections. So this makes easy that we do not need to handle explicit locks while handling the collections from different threads.

Concurrent Collections are slower compared to normal collections and little different, but thread safe. Even in the documentation and MSDN samples concurrent collections are mentioned in the parallel programming paradigm, not in a multi threaded application’s view.

I had some doubt on this, whether is it OK to use them in multi threaded environment; and raised a question in the MSDN, The thread seems to be useful and interesting.

I didn’t repost the question , answers and the code in my blog, as you can see them here


2 thoughts on “Concurrent Collections and TPL–.NET 4.0

  1. We would like to thank you all over again for the wonderful ideas you offered Janet when preparing her own post-graduate research plus, most importantly, with regard to providing all of the ideas in a single blog post. If we had been aware of your site a year ago, we will have been rescued from the pointless measures we were employing. Thank you very much.

Comments are closed.