Concurrent .NET
Concurrent collections for .NET
-
Download
-
SF page
-
Subversion repository
-
Introduction
Concurrent.NET is a library containing implementations of collection classes
that can be safely accessed and modified by multiple threads at the same time.
Right now it only contains an IDictionary implementation.
ConcurrentDictionary
ConcurrentDictionary is an IDictionary implementation that has the following characteristics:
- Multiple threads can access and modify the dictionary at the same time.
- Enumerators will always be valid. It is undefined whether a concurrent change to the dictionary will be picked up by the enumerator.
- For maximal concurrency, the implementation does not use locking. The implementation only relies on .NET's Interlocked class.
- It is highly compatible with Dictionary.
There are two aspects to keep in mind. First of all, the Count method is not very efficient. Internally, it iterates over all
keys. The result of Count is probably not very useful, because it can be out-dated the minute it is calculated. Second,
the implementation does not 'scale down'. Once you have used the dictionary with one million of entries and go back to one thousand,
the performance and memory characteristics will be worse than when you would start with one thousand entries. Scale down algorithms
require locking and this impacts concurrency too much.