From .NET Framework 4, a lot of thread-safe collections were added to the .NET repertoire. A new namespace, System.Threading.Concurrent, was also added. This included constructs like the following:
- IProducerConsumerCollection<T>
- BlockingCollection<T>
- ConcurrentDictionary<TKey,TValue>
When using the preceding structs, there is no need for any additional synchronization and both reading and updating can be done atomically.
Thread safety is not an entirely new concept in the case of collections. Even with older collections such as ArrayList and Hashtable, the Synchronized property was exposed, which made it possible to access these collections in a thread-safe manner. This, however, came with a performance hit, because to make the collection thread-safe, the entire collection was wrapped inside a lock with every read or...