Skip to content

aimenux/LazyConcurrentDictionaryDemo

Repository files navigation

.NET

LazyConcurrentDictionaryDemo

Using lazy concurrent dictionary to ensure thread safety for unsafe methods

ConcurrentDictionary<TKey,TValue> provides several methods for adding or updating key/value pairs in the dictionary. All these operations are atomic and are thread-safe with regards to all other operations on this class. The only exceptions are the methods that accept a delegate, that is, GetOrAdd and AddOrUpdate.

In this repo, i m comparing 2 implementations (default one versus lazy one) of concurrent dictionary when dealing with methods like GetOrAdd or AddOrUpdate :

  • DefaultConcurrentDictionary : use default implementation of concurrent dictionary, methods like GetOrAdd or AddOrUpdate are not thread safe (see link)

  • LazyConcurrentDictionary : use custom implementation (run once, lazy-loading) of concurrent dictionary, methods like GetOrAdd or AddOrUpdate are thread safe (see link)

LazyConcurrentDictionaryDemo

Tools : vs22, net 6.0

About

Using lazy concurrent dictionary to ensure thread safety for unsafe methods

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages