What are the real disadvantages of using ReaderWriterLock

We have a project aimed at RTM.NET 2.0 (yes, it should be RTM.NET 2.0, we have some Orthodox clients). And I'm just wondering what are the disadvantages of ReaderWriterLock ? Why is it so bad that everyone says "do not use it, try to use something else, like a lock statement"? If we could use .NET 3.5, I would definitely use ReaderWriterLockSlim , but with ReaderWriterLock I am a little ReaderWriterLock with all this warning coming from outside. Has anyone measured performance or something else? If there are any performance issues, by what payload can we meet them?

We have a classic situation from the point of view of the ReaderWriterLock main goal, i.e. repeated reading and rarely writes. Using the lock statement blocks all readers. This may not be a terrible problem for us, but if I could use ReaderWriterLock , I would be more satisfied. IMO representing multiple monitors is really a very bad idea.

+7
source share
2 answers

The following few posts may provide you with the ideas you are looking for.

ReaderWriterLockSlim performance comparison with ReaderWriterLock

Rico Mariani on using part of ReaderWriterLock this post explains some of the costs and usage scenarios of ReaderWriterLock, also check part 1 and part 2

Jeffrey Richter on ReaderWriterLock Alternative

+7
source

If you are really faced with an ideal use case for ReaderWriterLock (i.e. many simultaneous reads and multiple records), use it!

If you find it too slow, there are alternatives. Sanjivakumar provided some links in his answer. I also provided one of them:
Low locks in action: Reader-Writer lock implementation

I will quote from this link here:

  • Use read-write locks, as suggested in my first article. If lock perf is a problem, take the implementation here as a “replacement” for the .NET System.ReaderWriterLock. Feel free to use this implementation until Microsoft has installed the version in its library.
  • Spin locks are a truly valuable low-lock technique. It used simple but effective read-write locks written in managed code. This lock is much simpler than most implementations that I have seen, but is optimal for clost. The reason for this is that the use of BIG locks simplifies the design and analysis of the lock without sacrificing performance. Feel free to use the Spin lock implementation here to create other high-performance parallel constructs.
  • Even what is simple, like a Reader-Writer lock, has subtleties regarding its behavior (especially when you consider performance issues). Keeping simplicity really pays off here.
+1
source

All Articles