When you want to use a ReaderWriterLock
you declare it like this:
ReaderWriterLock rwLock = new ReaderWriterLock;
Well if you are doing that for all your different threads that are going to access some resource that you want to protect, they (presumably) are all using differnt ReaderWriterLock instances.
How is the ReaderWriterLock instance shared amongs threads?
Also, as a bonus, can someone confirm for me that what you are really "locking" is the ReaderWriterLock state, not any resource. Unlike lock(someResourceToLock)
, you aren't locking anything but the ReaderWriterLock instance's state (whether it is in read or write mode, and whether you are allowed to read and write yet).