O'Reilly logo

C# Multithreaded and Parallel Programming by Rodney Ringler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Concurrent collections

Another namespace that was introduced in .NET 4.0 is Systems.Collections.Concurrent. This is not directly a part of TPL, but it is often used in conjunction with TPL to provide much of the common parallel design patterns such as producer-consumer that we will discuss in Chapter 9, Pipeline and Producer-consumer Design Patterns.

System.Collections.Concurrent provides a thread-safe version of collection classes in the Systems.Collections namespace. These work very well in conjunction with tasks. This namespace has ConcurrentBag, which is a collection of objects such as ConcurrentDictionary, ConcurrentQueue, ConcurrentStack, and BlockingCollection to name the most popular ones.

All of these concurrent collections implement ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required