Show / Hide Table of Contents

Class AsyncReaderWriterLock

Represents asynchronous version of ReaderWriterLockSlim.

Inheritance
Object
QueuedSynchronizer
AsyncReaderWriterLock
Implements
ISynchronizer
IAsyncDisposable
Inherited Members
QueuedSynchronizer.ISynchronizer.HasWaiters
QueuedSynchronizer.CancelSuspendedCallers(CancellationToken)
QueuedSynchronizer.Dispose(Boolean)
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public class AsyncReaderWriterLock : QueuedSynchronizer, ISynchronizer, IAsyncDisposable
Remarks

This lock doesn't support recursion.

Constructors

| Improve this Doc View Source

AsyncReaderWriterLock()

Initializes a new reader/writer lock.

Declaration
public AsyncReaderWriterLock()

Properties

| Improve this Doc View Source

CurrentReadCount

Gets the total number of unique readers.

Declaration
public long CurrentReadCount { get; }
Property Value
Type Description
Int64
| Improve this Doc View Source

IsReadLockHeld

Gets a value that indicates whether the read lock taken.

Declaration
public bool IsReadLockHeld { get; }
Property Value
Type Description
Boolean
| Improve this Doc View Source

IsUpgradeableReadLockHeld

Gets a value that indicates whether the current upgradeable read lock taken.

Declaration
public bool IsUpgradeableReadLockHeld { get; }
Property Value
Type Description
Boolean
| Improve this Doc View Source

IsWriteLockHeld

Gets a value that indicates whether the write lock taken.

Declaration
public bool IsWriteLockHeld { get; }
Property Value
Type Description
Boolean

Methods

| Improve this Doc View Source

DisposeAsync()

Disposes this lock asynchronously and gracefully.

Declaration
public ValueTask DisposeAsync()
Returns
Type Description
ValueTask

The task representing graceful shutdown of this lock.

Remarks

If this lock is not acquired then the method just completes synchronously. Otherwise, it waits for calling of ExitReadLock(), method.

| Improve this Doc View Source

EnterReadLockAsync(CancellationToken)

Enters the lock in read mode asynchronously.

Declaration
public Task EnterReadLockAsync(CancellationToken token)
Parameters
Type Name Description
CancellationToken token

The token that can be used to abort lock acquisition.

Returns
Type Description
Task

The task representing acquisition operation.

Exceptions
Type Condition
ArgumentOutOfRangeException

Time-out value is negative.

ObjectDisposedException

This object has been disposed.

| Improve this Doc View Source

EnterReadLockAsync(TimeSpan, CancellationToken)

Enters the lock in read mode asynchronously.

Declaration
public Task EnterReadLockAsync(TimeSpan timeout, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
TimeSpan timeout

The interval to wait for the lock.

CancellationToken token

The token that can be used to abort lock acquisition.

Returns
Type Description
Task

The task representing acquisition operation.

Exceptions
Type Condition
ArgumentOutOfRangeException

Time-out value is negative.

ObjectDisposedException

This object has been disposed.

TimeoutException

The lock cannot be acquired during the specified amount of time.

| Improve this Doc View Source

EnterUpgradeableReadLockAsync(CancellationToken)

Enters the lock in upgradeable mode asynchronously.

Declaration
public Task EnterUpgradeableReadLockAsync(CancellationToken token)
Parameters
Type Name Description
CancellationToken token

The token that can be used to abort lock acquisition.

Returns
Type Description
Task

The task representing lock acquisition operation.

Exceptions
Type Condition
ArgumentOutOfRangeException

Time-out value is negative.

ObjectDisposedException

This object has been disposed.

| Improve this Doc View Source

EnterUpgradeableReadLockAsync(TimeSpan, CancellationToken)

Enters the lock in upgradeable mode asynchronously.

Declaration
public Task EnterUpgradeableReadLockAsync(TimeSpan timeout, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
TimeSpan timeout

The interval to wait for the lock.

CancellationToken token

The token that can be used to abort lock acquisition.

Returns
Type Description
Task

The task representing lock acquisition operation.

Exceptions
Type Condition
ArgumentOutOfRangeException

Time-out value is negative.

ObjectDisposedException

This object has been disposed.

TimeoutException

The lock cannot be acquired during the specified amount of time.

| Improve this Doc View Source

EnterWriteLockAsync(CancellationToken)

Enters the lock in write mode asynchronously.

Declaration
public Task EnterWriteLockAsync(CancellationToken token)
Parameters
Type Name Description
CancellationToken token

The token that can be used to abort lock acquisition.

Returns
Type Description
Task

The task representing lock acquisition operation.

Exceptions
Type Condition
ArgumentOutOfRangeException

Time-out value is negative.

ObjectDisposedException

This object has been disposed.

| Improve this Doc View Source

EnterWriteLockAsync(TimeSpan, CancellationToken)

Enters the lock in write mode asynchronously.

Declaration
public Task EnterWriteLockAsync(TimeSpan timeout, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
TimeSpan timeout

The interval to wait for the lock.

CancellationToken token

The token that can be used to abort lock acquisition.

Returns
Type Description
Task

The task representing lock acquisition operation.

Exceptions
Type Condition
ArgumentOutOfRangeException

Time-out value is negative.

ObjectDisposedException

This object has been disposed.

TimeoutException

The lock cannot be acquired during the specified amount of time.

| Improve this Doc View Source

ExitReadLock()

Exits read mode.

Declaration
public void ExitReadLock()
Remarks

Exiting from the lock is synchronous non-blocking operation. Lock acquisition is an asynchronous operation.

Exceptions
Type Condition
SynchronizationLockException

The caller has not entered the lock in read mode.

ObjectDisposedException

This object has been disposed.

| Improve this Doc View Source

ExitUpgradeableReadLock()

Exits upgradeable mode.

Declaration
public void ExitUpgradeableReadLock()
Remarks

Exiting from the lock is synchronous non-blocking operation. Lock acquisition is an asynchronous operation.

Exceptions
Type Condition
SynchronizationLockException

The caller has not entered the lock in upgradeable mode.

ObjectDisposedException

This object has been disposed.

| Improve this Doc View Source

ExitWriteLock()

Exits write mode.

Declaration
public void ExitWriteLock()
Remarks

Exiting from the lock is synchronous non-blocking operation. Lock acquisition is an asynchronous operation.

Exceptions
Type Condition
SynchronizationLockException

The caller has not entered the lock in write mode.

ObjectDisposedException

This object has been disposed.

| Improve this Doc View Source

TryEnterReadLock()

Attempts to obtain reader lock synchronously without blocking caller thread.

Declaration
public bool TryEnterReadLock()
Returns
Type Description
Boolean

true if lock is taken successfuly; otherwise, false.

Exceptions
Type Condition
ObjectDisposedException

This object has been disposed.

| Improve this Doc View Source

TryEnterReadLockAsync(TimeSpan)

Tries to enter the lock in read mode asynchronously, with an optional time-out.

Declaration
public Task<bool> TryEnterReadLockAsync(TimeSpan timeout)
Parameters
Type Name Description
TimeSpan timeout

The interval to wait for the lock.

Returns
Type Description
Task<Boolean>

true if the caller entered read mode; otherwise, false.

Exceptions
Type Condition
ArgumentOutOfRangeException

Time-out value is negative.

ObjectDisposedException

This object has been disposed.

| Improve this Doc View Source

TryEnterReadLockAsync(TimeSpan, CancellationToken)

Tries to enter the lock in read mode asynchronously, with an optional time-out.

Declaration
public Task<bool> TryEnterReadLockAsync(TimeSpan timeout, CancellationToken token)
Parameters
Type Name Description
TimeSpan timeout

The interval to wait for the lock.

CancellationToken token

The token that can be used to abort lock acquisition.

Returns
Type Description
Task<Boolean>

true if the caller entered read mode; otherwise, false.

Exceptions
Type Condition
ArgumentOutOfRangeException

Time-out value is negative.

ObjectDisposedException

This object has been disposed.

| Improve this Doc View Source

TryEnterUpgradeableReadLock()

Attempts to obtain upgradeable reader lock synchronously without blocking caller thread.

Declaration
public bool TryEnterUpgradeableReadLock()
Returns
Type Description
Boolean

true if lock is taken successfuly; otherwise, false.

Exceptions
Type Condition
ObjectDisposedException

This object has been disposed.

| Improve this Doc View Source

TryEnterUpgradeableReadLockAsync(TimeSpan)

Tries to enter the lock in upgradeable mode asynchronously, with an optional time-out.

Declaration
public Task<bool> TryEnterUpgradeableReadLockAsync(TimeSpan timeout)
Parameters
Type Name Description
TimeSpan timeout

The interval to wait for the lock.

Returns
Type Description
Task<Boolean>

true if the caller entered upgradeable mode; otherwise, false.

Exceptions
Type Condition
ArgumentOutOfRangeException

Time-out value is negative.

ObjectDisposedException

This object has been disposed.

| Improve this Doc View Source

TryEnterUpgradeableReadLockAsync(TimeSpan, CancellationToken)

Tries to enter the lock in upgradeable mode asynchronously, with an optional time-out.

Declaration
public Task<bool> TryEnterUpgradeableReadLockAsync(TimeSpan timeout, CancellationToken token)
Parameters
Type Name Description
TimeSpan timeout

The interval to wait for the lock.

CancellationToken token

The token that can be used to abort lock acquisition.

Returns
Type Description
Task<Boolean>

true if the caller entered upgradeable mode; otherwise, false.

Exceptions
Type Condition
ArgumentOutOfRangeException

Time-out value is negative.

ObjectDisposedException

This object has been disposed.

| Improve this Doc View Source

TryEnterWriteLock()

Attempts to obtain writer lock synchronously without blocking caller thread.

Declaration
public bool TryEnterWriteLock()
Returns
Type Description
Boolean

true if lock is taken successfuly; otherwise, false.

Exceptions
Type Condition
ObjectDisposedException

This object has been disposed.

| Improve this Doc View Source

TryEnterWriteLock(AsyncReaderWriterLock.LockStamp)

Attempts to acquire write lock without blocking.

Declaration
public bool TryEnterWriteLock(in AsyncReaderWriterLock.LockStamp stamp)
Parameters
Type Name Description
AsyncReaderWriterLock.LockStamp stamp

The stamp of the read lock.

Returns
Type Description
Boolean

true if lock is acquired successfully; otherwise, false.

Exceptions
Type Condition
ObjectDisposedException

This object has been disposed.

| Improve this Doc View Source

TryEnterWriteLockAsync(TimeSpan)

Tries to enter the lock in write mode asynchronously, with an optional time-out.

Declaration
public Task<bool> TryEnterWriteLockAsync(TimeSpan timeout)
Parameters
Type Name Description
TimeSpan timeout

The interval to wait for the lock.

Returns
Type Description
Task<Boolean>

true if the caller entered write mode; otherwise, false.

Exceptions
Type Condition
ArgumentOutOfRangeException

Time-out value is negative.

ObjectDisposedException

This object has been disposed.

| Improve this Doc View Source

TryEnterWriteLockAsync(TimeSpan, CancellationToken)

Tries to enter the lock in write mode asynchronously, with an optional time-out.

Declaration
public Task<bool> TryEnterWriteLockAsync(TimeSpan timeout, CancellationToken token)
Parameters
Type Name Description
TimeSpan timeout

The interval to wait for the lock.

CancellationToken token

The token that can be used to abort lock acquisition.

Returns
Type Description
Task<Boolean>

true if the caller entered write mode; otherwise, false.

Exceptions
Type Condition
ArgumentOutOfRangeException

Time-out value is negative.

ObjectDisposedException

This object has been disposed.

| Improve this Doc View Source

TryOptimisticRead()

Returns a stamp that can be validated later.

Declaration
public AsyncReaderWriterLock.LockStamp TryOptimisticRead()
Returns
Type Description
AsyncReaderWriterLock.LockStamp

Optimistic read stamp. May be invalid.

Exceptions
Type Condition
ObjectDisposedException

This object has been disposed.

Implements

ISynchronizer
System.IAsyncDisposable

Extension Methods

AsyncLockAcquisition.AcquireLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireUpgradeableReadLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireUpgradeableReadLockAsync<T>(T, CancellationToken)
ObjectExtensions.GetUserData<T>(T)
ObjectExtensions.IsOneOf<T>(T, IEnumerable<T>)
ObjectExtensions.IsOneOf<T>(T, T[])
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, Func<T, TResult1>, Func<T, TResult2>, out TResult1, out TResult2)
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, ValueFunc<T, TResult1>, ValueFunc<T, TResult2>, out TResult1, out TResult2)
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, Func<T, TResult1>, Func<T, TResult2>)
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, ValueFunc<T, TResult1>, ValueFunc<T, TResult2>)
ObjectExtensions.As<T>(T)
LockAcquisition.AcquireReadLock<T>(T)
LockAcquisition.AcquireReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireWriteLock<T>(T)
LockAcquisition.AcquireWriteLock<T>(T, TimeSpan)
LockAcquisition.AcquireUpgradeableReadLock<T>(T)
LockAcquisition.AcquireUpgradeableReadLock<T>(T, TimeSpan)
ExpressionBuilder.Const<T>(T)
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX