Class QueuedSynchronizer
Provides a framework for implementing asynchronous locks and related synchronization primitives that rely on first-in-first-out (FIFO) wait queues.
Inheritance
Implements
Inherited Members
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public class QueuedSynchronizer : Disposable, IDisposable
Remarks
This class is designed to provide better throughput rather than optimized response time. It means that it minimizes contention between concurrent calls and allows to process as many concurrent requests as possible by the cost of the execution time of a single method for a particular caller.
Properties
| Edit this page View SourceMeasurementTags
Sets a list of tags to be associated with each measurement.
Declaration
[CLSCompliant(false)]
public TagList MeasurementTags { init; }
Property Value
Type | Description |
---|---|
TagList |
Methods
| Edit this page View SourceCancelSuspendedCallers(CancellationToken)
Cancels all suspended callers.
Declaration
public void CancelSuspendedCallers(CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | token | The canceled token. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
ObjectDisposedException | The object has been disposed. |
Dispose(bool)
Releases all resources associated with this object.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing | Indicates whether the Dispose(bool) has been called directly or from finalizer. |
Overrides
Remarks
This method is not thread-safe and may not be used concurrently with other members of this instance.
Dispose(Exception?)
Releases all resources associated with this object.
Declaration
public void Dispose(Exception? reason)
Parameters
Type | Name | Description |
---|---|---|
Exception | reason | The exeption to be passed to all suspended callers. |
DisposeAsync()
Disposes this synchronization primitive gracefully.
Declaration
public ValueTask DisposeAsync()
Returns
Type | Description |
---|---|
ValueTask | The task representing asynchronous result. |
DisposeAsyncCore()
Releases managed resources associated with this object asynchronously.
Declaration
protected override ValueTask DisposeAsyncCore()
Returns
Type | Description |
---|---|
ValueTask | The task representing asynchronous execution of this method. |
Overrides
Remarks
This method makes sense only if derived class implements IAsyncDisposable interface.
GetSuspendedCallers()
Gets a list of suspended callers respecting their order in wait queue.
Declaration
public IReadOnlyList<object?> GetSuspendedCallers()
Returns
Type | Description |
---|---|
IReadOnlyList<object> | A list of suspended callers. |
Remarks
This method is introduced for debugging purposes only.
See Also
| Edit this page View SourceSetCallerInformation(object)
Sets caller information in DEBUG configuration.
Declaration
[Conditional("DEBUG")]
public void SetCallerInformation(object information)
Parameters
Type | Name | Description |
---|---|---|
object | information | The object that identifies the caller. |
Remarks
It is recommended to inject caller information immediately before calling of WaitAsync
method.
TrackSuspendedCallers(Func<object>?)
Enables capturing information about suspended callers in DEBUG configuration.
Declaration
[Conditional("DEBUG")]
public void TrackSuspendedCallers(Func<object>? callerInfoProvider = null)
Parameters
Type | Name | Description |
---|---|---|
Func<object> | callerInfoProvider | The optional factory of the information about the caller. |
Remarks
If callerInfoProvider
is provided then no need to use SetCallerInformation(object).