Class AsyncReaderWriterLock
Represents a source of a fair asynchronous reader-writer lock.
public sealed class AsyncReaderWriterLock
- Inheritance
-
AsyncReaderWriterLock
- Inherited Members
- Extension Methods
Remarks
Lock is not reentrant.
Constructors
AsyncReaderWriterLock()
Creates a new AsyncReaderWriterLock instance.
public AsyncReaderWriterLock()
Properties
Participants
Returns the total number of lock participants, which includes current lock holders and all waiters.
public int Participants { get; }
Property Value
Methods
EnterReadAsync(CancellationToken)
Asynchronously acquires a read lock from this reader-writer lock.
public ValueTask<AsyncReaderWriterLockReadToken> EnterReadAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenOptional CancellationToken that can be used to cancel pending read lock acquisition.
Returns
- ValueTask<AsyncReaderWriterLockReadToken>
New ValueTask<TResult> instance which returns an AsyncReaderWriterLockReadToken value.
Exceptions
- OperationCanceledException
When provided
cancellationTokenwas cancelled before the read lock was acquired.
EnterUpgradeableReadAsync(CancellationToken)
Asynchronously acquires an upgradeable read lock from this reader-writer lock.
public ValueTask<AsyncReaderWriterLockUpgradeableReadToken> EnterUpgradeableReadAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenOptional CancellationToken that can be used to cancel pending upgradeable read lock acquisition.
Returns
- ValueTask<AsyncReaderWriterLockUpgradeableReadToken>
New ValueTask<TResult> instance which returns an AsyncReaderWriterLockUpgradeableReadToken value.
Exceptions
- OperationCanceledException
When provided
cancellationTokenwas cancelled before the upgradeable read lock was acquired.
EnterWriteAsync(CancellationToken)
Asynchronously acquires a write lock from this reader-writer lock.
public ValueTask<AsyncReaderWriterLockWriteToken> EnterWriteAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenOptional CancellationToken that can be used to cancel pending write lock acquisition.
Returns
- ValueTask<AsyncReaderWriterLockWriteToken>
New ValueTask<TResult> instance which returns an AsyncReaderWriterLockWriteToken value.
Exceptions
- OperationCanceledException
When provided
cancellationTokenwas cancelled before the write lock was acquired.
TrimExcess()
Attempts to discard unused resources.
public void TrimExcess()
TryEnterRead(out bool)
Attempts to synchronously acquire a read lock from this reader-writer lock.
public AsyncReaderWriterLockReadToken TryEnterRead(out bool entered)
Parameters
enteredboolout parameter which specifies whether the read lock was acquired.
Returns
- AsyncReaderWriterLockReadToken
New AsyncReaderWriterLockReadToken value. When
enteredis false, then returned instanced will be a default value.
TryEnterUpgradeableRead(out bool)
Attempts to synchronously acquire an upgradeable read lock from this reader-writer lock.
public AsyncReaderWriterLockUpgradeableReadToken TryEnterUpgradeableRead(out bool entered)
Parameters
enteredboolout parameter which specifies whether the upgradeable read lock was acquired.
Returns
- AsyncReaderWriterLockUpgradeableReadToken
New AsyncReaderWriterLockUpgradeableReadToken value. When
enteredis false, then returned instanced will be a default value.
TryEnterWrite(out bool)
Attempts to synchronously acquire a write lock from this reader-writer lock.
public AsyncReaderWriterLockWriteToken TryEnterWrite(out bool entered)
Parameters
enteredboolout parameter which specifies whether the write lock was acquired.
Returns
- AsyncReaderWriterLockWriteToken
New AsyncReaderWriterLockWriteToken value. When
enteredis false, then returned instanced will be a default value.