Is multi-level ConcurrentDictionary still thread-safe?
-
31-10-2019 - |
Question
I have four level data structure defined like this:
Dictionary<Type1, Dictionary<Type2, Dictionary<Type3, List<Type4>>>>
The whole thing is encapsulated in a class which also maintains thread-safety. Currently it just locks whole collection while it reads/manipulates the data (reading is by orders of magnitude more common than writing).
I was thinking of replacing the Dictionary
with ConcurrentDictionary
and List
with ConcurrentBag
(its items don't have to be ordered).
If I do so, can I just eliminate the locks and be sure the concurrent collections will do their job correctly?
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow