In this lecture we'll go over why regular collections like
List<T> and
Dictionary<TKey, TValue> break under multithreading (race conditions), why a single
lock is often not enough, and how the thread-safe collections from
System.Collections.Concurrent solve these problems. We'll look at the key structures:
ConcurrentQueue<T>,
ConcurrentStack<T>,
ConcurrentBag<T>,
ConcurrentDictionary<TKey, TValue>, their scenarios (producer–consumer, caching, object pools) and how to choose between them.