public class ReaderWriterLock { public ReaderWriterLock() public bool IsReaderLockHeld {get;} public bool IsWriterLockHeld {get;} public int WriterSeqNum {get;} public void AcquireReaderLock(int millisecondsTimeout); public void AcquireReaderLock(TimeSpan timeout) public void AcquireWriterLock(int millisecondsTimeout); public void AcquireWriterLock(TimeSpan timeout) public void ReleaseReaderLock(); public void ReleaseWriterLock(); public LockCookie UpgradeToWriterLock(int millisecondsTimeout); public LockCookie UpgradeToWriterLock(TimeSpan timeout) public void DowngradeFromWriterLock(ref LockCookie lockCookie); public LockCookie ReleaseLock(); public void RestoreLock(ref LockCookie lockCookie); public bool AnyWritersSince(int seqNum); }
Constructor
Property that returns TRUE if the reader lock is held by the current thread
Property that returns TRUE if the writer lock is held by the current thread
Property that returns the current writer sequence number. The caller should be a reader or writer for getting meaningful results
Acquires reader lock. The thread will block if a different thread has writer lock.
Acquires writer lock. The thread will block if a different thread has reader lock. It will dead lock if this thread has reader lock. Use UpgardeToWriterLock when you are not sure if the thread has reader lock
Releases reader lock.
Releases writer lock.
Upgrades the thread to a writer. If the thread has is a reader, it is possible that the reader lock was released before writer lock was acquired.
Restores the lock status of the thread to the one it was in when it called UpgradeToWriterLock.
Releases the lock irrespective of the number of times the thread
acquired the lock
Restores the lock status of the thread to the one it was in when it called ReleaseLock.
Returns true if there were intermediate writes since the sequence number was obtained. The caller should be a reader or writer for getting meaningful results