c# - Optimized ReaderWriterLock Read Access -
So it is my understanding that to read both the reader Wernerlock (or more specifically ReaderWriterLockSlim), both need to read and write Lock a Mute X. I would like to optimize the reading reach of the lock, such that if no one is left unpiled, no lock will be required. (And I'm ready to abandon the writing performance, read some obstacles, read slow and second fast, etc. And, if necessary, read as fast as possible.)
So, how will it, or better than that, whether there is a framework or "standard" implementation can one point me? (Or if I have been misunderstood and it is already supported, great!)
So for my piece: It appears that if someone has a counter for the number of readers / writers (The increase protected by the interlock), it would be enough to read whether the author's count was non-zero, and only got the lock (and increment within the acquired lock).
Writers always get increment, lock, reader count goes up to 0 (readers are always ready to accept, or the reader count completely bypasses in an optimistic scenario. ), And finally decrease. (When I am only protecting one value, then we block in any block, or potentially clean all pending readers / writers, it would be good to throw some priority also, but for now I I will give up ..)
So .. anyone has seen something like this or has any suggestions? If nothing is after nothing, then I am happy to throw an initial implementation together and talk more strongly.
What you have described is at the original level, how does a reader / author already work Readers / writers do not need to exclude a muted exchange using lock control records and authors (and, actually, a mutex means readers will block each other, while in fact many concurrent readers allowed - This is the full state of the lock type!).
So yes, there is a framework / standard implementation for this: ReaderWriterLockSlim
. I really doubt that you will be able to write a reader / writer lock with better performance. In any case - are you sure this lock is the root cause of your performance problems?
Comments
Post a Comment