c# - Is it safe to call Add on SortedDictionary in one thread and get Item in another? -
i'm working on making sorteddictionary thread safe , thing i'm not sure is: safe have call add sorteddictionary in 1 thread, this:
dictionary.add(key, value);
and item dictionary in thread, this:
variable = dictionary[key];
there no explicit enumeration in either of places, looks safe, great sure it.
no, not safe read , write sorteddictionary<k,v>
concurrently: adding element sorted dictionary may involve re-balancing of tree, may cause concurrent read operation take wrong turn while navigating element of interest.
in order fix problem need either wrap instance of sorteddictionary<k,v>
in class performs explicit locking, or roll own collection compatible interfaces implemented sorteddictionary<k,v>
.
Comments
Post a Comment