Let's say I have a dictionary that contains key-values where the value is an object with a lock. Each process needs to get the lock to modify the specific object, but the keys in the dictionary are stable.
Now, as I said before, if a new key is to be added with a new object (not very often), is there a way to use a lock that will exclude the other processes from accessing the objects while I add the key to dictionary?
The reason for this, is that I can't see the point in making the dictionary exclusive to all processes when it is unlikely that they will operate on the same objects, so the objects are the only ones that need to be waited on. When I modify the integrity of the dictionary, I want to block every process from accessing it, but while not, I want them to have parallel access to it.
Please ask if I am not clear.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…