Show / Hide Table of Contents

Class Synchronizer

Provides a framework for implementing asynchronous locks and related synchronization primitives that doesn't rely on first-in-first-out (FIFO) wait queues.

Inheritance
Object
Synchronizer
AsyncCountdownEvent
AsyncManualResetEvent
Implements
ISynchronizer
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public abstract class Synchronizer : Disposable, ISynchronizer
Remarks

Derived synchronization primitives more efficient in terms of memory pressure in comparison with QueuedSynchronizer. It shares the same instance of Task<TResult> under contention for all waiters.

Properties

| Improve this Doc View Source

IsSet

Determines whether this event in signaled state.

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

Methods

| Improve this Doc View Source

Dispose(Boolean)

Releases all resources associated with exclusive lock.

Declaration
protected override void Dispose(bool disposing)
Parameters
Type Name Description
Boolean disposing

Indicates whether the Dispose(Boolean) has been called directly or from finalizer.

Remarks

This method is not thread-safe and may not be used concurrently with other members of this instance.

| Improve this Doc View Source

WaitAsync(TimeSpan, CancellationToken)

Suspends the caller until this event is set.

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

The number of time to wait before this event is set.

CancellationToken token

The token that can be used to cancel waiting operation.

Returns
Type Description
Task<Boolean>

true, if this event was set; otherwise, false.

Exceptions
Type Condition
ObjectDisposedException

The current instance has already been disposed.

ArgumentOutOfRangeException

timeout is negative.

OperationCanceledException

The operation has been canceled.

| Improve this Doc View Source

WaitAsync<T>(Predicate<T>, T, CancellationToken)

Suspends the caller until this event is set.

Declaration
public Task WaitAsync<T>(Predicate<T> condition, T arg, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
Predicate<T> condition

Additional condition that must be checked before suspension.

T arg

The argument to be passed to the predicate.

CancellationToken token

The token that can be used to cancel waiting operation.

Returns
Type Description
Task

true, if this event was set; otherwise, false.

Type Parameters
Name Description
T

The type of predicate parameter.

Remarks

If given predicate returns true then caller will not be suspended.

Exceptions
Type Condition
ObjectDisposedException

The current instance has already been disposed.

OperationCanceledException

The operation has been canceled.

| Improve this Doc View Source

WaitAsync<T>(Predicate<T>, T, TimeSpan, CancellationToken)

Suspends the caller until this event is set.

Declaration
public Task<bool> WaitAsync<T>(Predicate<T> condition, T arg, TimeSpan timeout, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
Predicate<T> condition

Additional condition that must be checked before suspension.

T arg

The argument to be passed to the predicate.

TimeSpan timeout

The number of time to wait before this event is set.

CancellationToken token

The token that can be used to cancel waiting operation.

Returns
Type Description
Task<Boolean>

true, if this event was set; otherwise, false.

Type Parameters
Name Description
T

The type of predicate parameter.

Remarks

If given predicate returns true then caller will not be suspended.

Exceptions
Type Condition
ObjectDisposedException

The current instance has already been disposed.

ArgumentOutOfRangeException

timeout is negative.

OperationCanceledException

The operation has been canceled.

| Improve this Doc View Source

WaitAsync<T1, T2>(Func<T1, T2, Boolean>, T1, T2, CancellationToken)

Suspends the caller until this event is set.

Declaration
public Task WaitAsync<T1, T2>(Func<T1, T2, bool> condition, T1 arg1, T2 arg2, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
Func<T1, T2, Boolean> condition

Additional condition that must be checked before suspension.

T1 arg1

The first argument to be passed to the predicate.

T2 arg2

The second argument to be passed to the predicate.

CancellationToken token

The token that can be used to cancel waiting operation.

Returns
Type Description
Task

true, if this event was set; otherwise, false.

Type Parameters
Name Description
T1

The type of the first predicate parameter.

T2

The type of the second predicate parameter.

Remarks

If given predicate returns true then caller will not be suspended.

Exceptions
Type Condition
ObjectDisposedException

The current instance has already been disposed.

OperationCanceledException

The operation has been canceled.

| Improve this Doc View Source

WaitAsync<T1, T2>(Func<T1, T2, Boolean>, T1, T2, TimeSpan, CancellationToken)

Suspends the caller until this event is set.

Declaration
public Task<bool> WaitAsync<T1, T2>(Func<T1, T2, bool> condition, T1 arg1, T2 arg2, TimeSpan timeout, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
Func<T1, T2, Boolean> condition

Additional condition that must be checked before suspension.

T1 arg1

The first argument to be passed to the predicate.

T2 arg2

The second argument to be passed to the predicate.

TimeSpan timeout

The number of time to wait before this event is set.

CancellationToken token

The token that can be used to cancel waiting operation.

Returns
Type Description
Task<Boolean>

true, if this event was set; otherwise, false.

Type Parameters
Name Description
T1

The type of the first predicate parameter.

T2

The type of the second predicate parameter.

Remarks

If given predicate returns true then caller will not be suspended.

Exceptions
Type Condition
ObjectDisposedException

The current instance has already been disposed.

ArgumentOutOfRangeException

timeout is negative.

OperationCanceledException

The operation has been canceled.

Explicit Interface Implementations

| Improve this Doc View Source

ISynchronizer.HasWaiters

Declaration
bool ISynchronizer.HasWaiters { get; }
Returns
Type Description
Boolean

Implements

ISynchronizer

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