C# 8 Concurrent Collections
Learn to use concurrent collections effectively to store data in a multithreaded environment, keeping the code efficient and avoiding data corruption and race conditions.
What you'll learn
Making applications concurrent can be a vital part of ensuring good responsiveness and high performance, but standard collections are not designed for concurrent environments.
In this course, C# Concurrent Collections, you’ll learn how to use concurrent collections to bring the power of manipulating data in collections to multithreaded scenarios by thinking about problems in a concurrent way.
First, you’ll discover how to avoid race conditions and data corruption, and how to use lambdas and closures to complete concurrent collection operations in a thread-safe way.
Next, you’ll explore producer-consumer collections, such as stacks and queues. Then, you'll learn how to safely consume all items from a queue when you don’t know if other threads might be adding other items.
Finally, you’ll delve into good coding practices to keep your concurrent collection code efficient.
By the end of this course, you’ll understand how to safely store data in collections and have multiple threads access that data concurrently, while avoiding the thread synchronization bugs that can otherwise plague concurrent code.
Table of contents
- Overview 1m
- Introducing the SellShirts Demo 1m
- Storing Shirts in an ImmutableArray 3m
- The Stock Controller and the Dictionary 3m
- Generating Random Numbers 2m
- The Main() Method 1m
- Simulating Serving Customers 4m
- Adding Concurrency and ConcurrentDictionary 3m
- The Indexer vs. TryGetValue() 3m
- Fixing the Code to Allow for Failure 3m
- Remove() vs. TryRemove() 3m
- Concurrent Collection State Can Be Uncertain 3m
- Summary 1m
- Overview 1m
- Introducing the BuyAndSell Demo 2m
- Storing the Stock in a Dictionary 2m
- Updating a Standard Dictionary 2m
- Summing Values with LINQ and Checking for Errors 2m
- Modelling Serving a Customer 2m
- Adding Concurrency 2m
- Race Conditions and Data Corruption 4m
- Updating Atomically with TryUpdate() 3m
- Introducing AddOrUpdate() 2m
- Interlocked.Add() 1m
- Protecting against Race Conditions 2m
- Lambdas to Conditionally Update the Dictionary 3m
- Solving the Update Problem with a Closure 3m
- GetOrAdd() to Read the Dictionary 2m
- Summary 1m
- Overview 1m
- Concurrent Collections and Performance 1m
- The Dictionary Benchmark Demo 4m
- Benchmarking with Multiple Threads 2m
- Running the Benchmark 3m
- Use Shared State Sparingly 2m
- Using ConcurrentDictionary Correctly 2m
- The Problem with Count 3m
- Aggregate State 2m
- Good Practices for State 2m
- Summary 1m