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.
Implements
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 SourceIsSet
Determines whether this event in signaled state.
Declaration
public bool IsSet { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
Methods
| Improve this Doc View SourceDispose(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.
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 |
|
| OperationCanceledException | The operation has been canceled. |
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. |
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 |
|
| OperationCanceledException | The operation has been canceled. |
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. |
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 |
|
| OperationCanceledException | The operation has been canceled. |
Explicit Interface Implementations
| Improve this Doc View SourceISynchronizer.HasWaiters
Declaration
bool ISynchronizer.HasWaiters { get; }
Returns
| Type | Description |
|---|---|
| Boolean |