Chapter 4. Concurrent Collections

WHAT'S IN THIS CHAPTER?

  • Understanding the features offered by concurrent collections

  • Working with the concurrent collections found in the new System.Collection.Concurrent namespace

  • Working with concurrent queues

  • Implementing a parallel producer-consumer pattern

  • Working with multiple producers and consumers

  • Designing pipelines by using concurrent collections

  • Working with concurrent stacks

  • Transforming arrays and unsafe collections into concurrent collections

  • Working with concurrent bags

  • Understanding the IProducerConsumerCollection interface

  • Understanding bounding and blocking capabilities offered by blocking concurrent collections

  • Cancelling operations on concurrent collections

  • Implementing a filtering pipeline with many BlockingCollection instances

Task-based programming, imperative data, and task parallelism require arrays, lists, and collections capable of supporting updates concurrently. Before .NET Framework 4, it was necessary to add complex code to synchronize the operations performed in shared arrays, lists, and collections when they were updated by multiple threads. Now, you can work with the new concurrent collections to simplify the code and to achieve the best performance. These collections allow you to solve complex algorithms with simpler code. However, because they were just introduced with .NET Framework 4, you need to learn five new classes and one new interface.

This chapter is about the new classes and the new interface that allow you to work ...

Get Professional Parallel Programming with C#: Master Parallel Extensions With .NET 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.