C# Concurrent Collections
Learn how to use concurrent collections in multithreaded code! This course will teach you the correct use of ConcurrentDictionary, as well as introducing you to producer-consumer scenarios and the blocking collection.
What you'll learn
Learn how to use concurrent collections in multithreaded code! This course is a comprehensive introduction to the concurrent collections. It shows you how to use each of the main collection types: ConcurrentDictionary, ConcurrentQueue, ConcurrentBag, and ConcurrentStack. You'll learn the correct techniques for using these collections to avoid bugs such as race conditions, and also how to use BlockingCollection with the concurrent collections correctly in producer-consumer scenarios. The course rounds off with a look at some concurrent collection best practices.
Table of contents
- Welcome and Course Overview 4m
- Module Overview 1m
- Introducing the Sample: The Geek Clothing Company 4m
- Making the Queue Multithreaded 5m
- Fixing the Code with ConcurrentQueue<T> 3m
- Why Did Queue<T>.EnQueue() Fail? 5m
- Atomic Methods 2m
- Why Locks Aren't Always So Great 4m
- Concurrent Collections Don't Always Block Threads 3m
- Concurrent Collections and Race Conditions 3m
- What Concurrent Collections Are There? 3m
- IProducerConsumerCollection<T> and BlockingCollection<T> 2m
- Partitioner<T> and OrderablePartitioner<T> 3m
- Module Summary 1m
- Module Overview 3m
- Basic Dictionary Operations 3m
- Converting to ConcurrentDictionary 3m
- Why Is ConcurrentDictionary.Add() Hidden? 3m
- Some Thread-friendly Methods 2m
- The TryXXX Pattern and TryGetValue() 2m
- The TryAdd() Method 2m
- The TryRemove() Method 1m
- The TryUpdate() Method 4m
- The Problem with TryUpdate() 3m
- The AddOrUpdate() Method 4m
- Beware Race Conditions! 2m
- Do Each Operation in One Method Call! 4m
- The GetOrAdd() Method 3m
- Module Summary 2m
- Module Overview 1m
- Introducing the BuyAndSell Sample 3m
- The Buy-sell Algorithm 5m
- Using AddOrUpdate() to Update the Concurrent Dictionary 4m
- Using Interlocked.Add() to Update the Total 0m
- Thread-safe ... But No Locks! 2m
- Why Can't We Use TryUpdate()? 2m
- Conditionally Updating the Concurrent Dictionary 3m
- Conditional Logic in AddOrUpdate(): Using a Lambda 3m
- The Problem of Side-effects 3m
- AddOrUpdate(): Avoiding Conditional Logic 4m
- Summing ConcurrentDictionary Values Using Linq 3m
- Using GetOrAdd() to Display Values 1m
- Let's Stress-test the Demo! 2m
- Module Summary 2m
- Module Overview 1m
- Introducing the SalesBonuses Sample 3m
- Logging Trades to the To-do Queue 2m
- Enqueuing to the Concurrent Queue 1m
- The Consumer Loop: Monitoring the Concurrent Queue 3m
- The Main Program Flow 2m
- Calculating Bonuses 4m
- The Problem of Polling 1m
- Introducing the Blocking Collection 2m
- Using BlockingCollection<T>.Take() to Avoid Polling 3m
- BlockingCollection<T> and IProducerConsumerCollection<T> 2m
- BlockingCollection<T> Additional Features 2m
- Module Summary 1m
- Module Overview 2m
- Concurrent Collections and Performance 5m
- Benchmarking ConcurrentDictionary with Multiple Threads 5m
- Access Shared State Sparingly 4m
- ConcurrentDictionary Uses Fine-grained Locking 2m
- Count, IsEmpty, Etc. Perform Badly on ConcurrentDictionary 3m
- Avoid Relying on the State of Concurrent Collections 2m
- Enumerating While Modifying a Standard Collection 2m
- Enumerating While Modifying a Concurrent Collection 3m
- When Do You Need Concurrent Collections? 6m
- Module Summary 2m
- Thanks to the Models… 2m
- Course Summary 2m