I have a multi-threaded C# application. There is one dictionary that is accessed from N different threads at the same time. 99% of the calls are from thread A and the rest are from B, C, ...
Right now, I'm just locking the dictionary on each access. But it seems wasteful because 99% of the time that I'm calling lock, thread A already has the lock.
What would a more efficient way of doing this be?
Maybe some type of .Begin and .End calls could be required for threads B, C, ... and then Thread A would only have to check one bit on each call to see if any of the other threads are using the dictionary. Does anyone have a code sample of something like this implemented in a thread safe way?