Is layered ConcurrentDictionary still thread protected?

I have a four-level data structure defined as follows:

Dictionary<Type1, Dictionary<Type2, Dictionary<Type3, List<Type4>>>>

All of this is encapsulated in a class that also supports thread safety. Currently, it just blocks the whole collection when it reads / processes data (reading is an order of magnitude larger than writing).

I was thinking of replacing Dictionarywith ConcurrentDictionaryand Listwith ConcurrentBag(its elements do not need to be ordered).

If I do this, can I just remove the locks and make sure that parallel collections will do their job correctly?

+3
source share
2 answers

, . , , :

, . , GetEnumerator.

, , , ReaderWriterLockSlim, , .

+3

.. , - , :

Dictionary<Tuple<Type1, Type2, Type3>, List<Type4>> ?

, - ( ) O (1) ( , ConcurrentDictionary), , . ConcurrentDictionary.

, Type2 Type1, , , . ?

+6

Source: https://habr.com/ru/post/1790921/


All Articles