c# - Is multi-level ConcurrentDictionary still thread-safe? -


i have 4 level data structure defined this:

dictionary<type1, dictionary<type2, dictionary<type3, list<type4>>>> 

the whole thing encapsulated in class maintains thread-safety. locks whole collection while reads/manipulates data (reading orders of magnitude more common writing).

i thinking of replacing dictionary concurrentdictionary , list concurrentbag (its items don't have ordered).

if so, can eliminate locks , sure concurrent collections job correctly?

the concurrent collections prevent data corruption , crashes, code won't semantically equivalent current one. example, if iterate 1 of concurrent dictionaries, some of items may belong different updates:

the enumerator returned dictionary safe use concurrently reads , writes dictionary, not represent moment-in-time snapshot of dictionary. contents exposed through enumerator may contain modifications made dictionary after getenumerator called.

if want maintain exact behavior have now, yet save on cost of locking, may want lock readerwriterlockslim suited cases more reads writes.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -