I have such code that runs from many threads at the same time (on common a and b objects of type Dictionary<int, double> ):
foreach (var key in a.Keys.Union(b.Keys)) { dist += Math.Pow(b[key] - a[key], 2); }
Dictionaries do not change throughout the life of the threads. It is safe? So far, everything is in order, but I wanted to be sure.
source share