Export (0) Print
Expand All

ReaderWriterLock

ReaderWriterLock allows multiple threads to read a resource concurrently, but requires a thread to wait for an exclusive lock in order to write to the resource.

Within your application you might use a ReaderWriterLock to provide cooperative synchronization among threads that access a shared resource. In this case, locks are taken on the ReaderWriterLock itself. As with any thread synchronization mechanism, you must ensure that no threads bypass the ReaderWriterLock.

Alternatively, you might design a class that encapsulates a resource. This class might use a ReaderWriterLock to implement its locking scheme for the resource. ReaderWriterLock uses an efficient design, and thus can be used to synchronize individual objects.

Structure your application to minimize the duration of reads and writes. Long writes hurt throughput directly because the write lock is exclusive. Long reads block waiting writers, and if there is at least one thread waiting for the write lock then threads that request new reader locks will be blocked as well.

See Also

Threading | Threading Objects and Features | ReaderWriterLock Class | Monitor

Show:
© 2014 Microsoft