A colleague of mine recently stated it is fine for multiple read write threads to access a c# dictionary if you don’t mind retreiving stale data. His justification was that since the program would reapeatedly read from the dictionary, stale data won’t be an issue.
I told him that locking a collection was always necessary when you have a writer thread because the internal state of the collection will get corrupted.
Am I mistaken?
You are correct, and your colleague is wrong: one can access a dictionary from multiple threads only in the absence of writers.
.NET 4.0 adds
ConcurrentDictionary<K,T>class that does precisely what its name implies.