Class ReaderWriterLock
- Namespace
- Jitter2.Parallelization
- Assembly
- Jitter2.dll
Provides a lightweight reader-writer lock optimized for rare write operations.
public sealed class ReaderWriterLock
- Inheritance
-
ReaderWriterLock
- Inherited Members
Remarks
Multiple readers can hold the lock concurrently, but writers have exclusive access. This implementation uses spin-waiting and is best suited for short critical sections.
This lock is non-recursive and thread-affine. Each successful acquisition must be released exactly once by the same thread that acquired it. Recursive acquisition, read-to-write upgrades, write-to-read downgrades, and releasing a lock acquired by another thread are not supported.
Thread-safe when used according to this contract. All synchronization is performed using atomic operations and memory barriers.
Methods
EnterReadLock()
Acquires the read lock.
public void EnterReadLock()
Remarks
Multiple threads can hold the read lock simultaneously. This method blocks while a writer holds the lock.
The lock must be released exactly once by the acquiring thread using ExitReadLock().
EnterWriteLock()
Acquires the write lock with exclusive access.
public void EnterWriteLock()
Remarks
This method blocks until all readers and other writers have released the lock.
The lock must be released exactly once by the acquiring thread using ExitWriteLock().
ExitReadLock()
Releases a read lock previously acquired by the current thread.
public void ExitReadLock()
Remarks
Must be called exactly once for each successful call to EnterReadLock() and on the same thread that acquired the lock.
ExitWriteLock()
Releases the write lock held by the current thread.
public void ExitWriteLock()
Remarks
Must be called exactly once after a successful call to EnterWriteLock() and on the same thread that acquired the lock.