- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Use ReaderWriter Lock in C#
ReaderWriterLock synchronize access to a resource.
A ReaderWriterLock has better throughput than a Monitor, which is one-at-a-time lock. This works for a situation when a resource is changed rarely.
Let us see how to declare a ReaderWriter lock in C# −
static ReaderWriterLock r = new ReaderWriterLock();
The following are the properties of a ReaderWriter lock in C# −
Sr.No. | Property & Description |
---|---|
1 | IsReaderLockHeld Gets a value indicating whether the current thread holds a reader lock. |
2 | IsWriterLockHeld Gets a value indicating whether the current thread holds a Writer lock. |
3 | WriterSeqNum Current sequence number |
The following are some of the methods of ReaderWriter lock −
Sr.No. | Method & Description |
---|---|
1 | AcquireReaderLock(TimeSpan) Acquires a reader lock, using a TimeSpan value for the time-out. |
2 | AcquireWriterLock(TimeSpan) Acquires a Writer lock, using a TimeSpan value for the time-out. |
3 | Equals(Object) Determines whether the specified object is equal to the current object.(Inherited from Object.) |
4 | GetHashCode() Default hash |
5 | GetType() Type of the current instance |
6 | ReleaseReaderLock() Lock Count decrements |