Show / Hide Table of Contents

Class AsyncBarrier

Enables multiple tasks to cooperatively work on an algorithm in parallel through multiple phases.

Inheritance
Object
Disposable
AsyncBarrier
Implements
IAsyncEvent
IDisposable
Inherited Members
Disposable.IsDisposed
Disposable.ThrowIfDisposed()
Disposable.DisposedTask
Disposable.GetDisposedTask<T>()
Disposable.TrySetDisposedException<T>(TaskCompletionSource<T>)
Disposable.TrySetDisposedException(TaskCompletionSource)
Disposable.DisposeAsync()
Disposable.Dispose()
Disposable.Dispose(IEnumerable<Nullable<IDisposable>>)
Disposable.DisposeAsync(IEnumerable<Nullable<IAsyncDisposable>>)
Disposable.Dispose(Nullable<IDisposable>[])
Disposable.DisposeAsync(Nullable<IAsyncDisposable>[])
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public class AsyncBarrier : Disposable, IAsyncEvent
Remarks

This is asynchronous version of with small differences:

  • Post-phase action is presented by virtual method PostPhase(Int64).
  • It it possible to wait for phase completion without signal.
  • It is possible to signal without waiting of phase completion.
  • Post-phase action is asynchronous.
  • Number of phases is limited by Int64 data type.

Constructors

| Improve this Doc View Source

AsyncBarrier(Int64)

Initializes a new Barrier withe given number of participating tasks.

Declaration
public AsyncBarrier(long participantCount)
Parameters
Type Name Description
Int64 participantCount

The number of participating tasks.

Properties

| Improve this Doc View Source

CurrentPhaseNumber

Gets the number of the barrier's current phase.

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

ParticipantCount

Gets the total number of participants in the barrier.

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

ParticipantsRemaining

Gets the number of participants in the barrier that haven't yet signaled in the current phase.

Declaration
public long ParticipantsRemaining { get; }
Property Value
Type Description
Int64

Methods

| Improve this Doc View Source

AddParticipant()

Notifies this barrier that there will be additional participant.

Declaration
public long AddParticipant()
Returns
Type Description
Int64

The phase number of the barrier in which the new participants will first participate.

| Improve this Doc View Source

AddParticipants(Int64)

Notifies this barrier that there will be additional participants.

Declaration
public long AddParticipants(long participantCount)
Parameters
Type Name Description
Int64 participantCount

The number of additional participants to add to the barrier.

Returns
Type Description
Int64

The phase number of the barrier in which the new participants will first participate.

| Improve this Doc View Source

Dispose(Boolean)

Declaration
protected override void Dispose(bool disposing)
Parameters
Type Name Description
Boolean disposing
Overrides
Disposable.Dispose(Boolean)
| Improve this Doc View Source

DisposeAsyncCore()

Declaration
protected override ValueTask DisposeAsyncCore()
Returns
Type Description
ValueTask
Overrides
Disposable.DisposeAsyncCore()
| Improve this Doc View Source

PostPhase(Int64)

The action to be executed after each phase.

Declaration
protected virtual ValueTask PostPhase(long phase)
Parameters
Type Name Description
Int64 phase

The current phase number.

Returns
Type Description
ValueTask

A task representing post-phase asynchronous execution.

| Improve this Doc View Source

RemoveParticipant()

Notifies this barrier that there will be one less participant.

Declaration
public void RemoveParticipant()
Remarks

This method may resume all tasks suspended by WaitAsync(TimeSpan, CancellationToken) and SignalAndWaitAsync(TimeSpan, CancellationToken) methods.

| Improve this Doc View Source

RemoveParticipants(Int64)

Notifies this barrier that there will be fewer participants.

Declaration
public void RemoveParticipants(long participantCount)
Parameters
Type Name Description
Int64 participantCount

The number of additional participants to remove from the barrier.

Remarks

This method may resume all tasks suspended by WaitAsync(TimeSpan, CancellationToken) and SignalAndWaitAsync(TimeSpan, CancellationToken) methods.

| Improve this Doc View Source

SignalAndWaitAsync(CancellationToken)

Signals that a participant has reached the barrier and waits for all other participants to reach the barrier as well.

Declaration
public async ValueTask SignalAndWaitAsync(CancellationToken token = null)
Parameters
Type Name Description
CancellationToken token

The token that can be used to cancel the waiting operation.

Returns
Type Description
ValueTask

The task representing waiting operation.

| Improve this Doc View Source

SignalAndWaitAsync(TimeSpan, CancellationToken)

Signals that a participant has reached the barrier and waits for all other participants to reach the barrier as well.

Declaration
public async ValueTask<bool> SignalAndWaitAsync(TimeSpan timeout, CancellationToken token = null)
Parameters
Type Name Description
TimeSpan timeout

The time to wait for phase completion.

CancellationToken token

The token that can be used to cancel the waiting operation.

Returns
Type Description
ValueTask<Boolean>

true if all other participants reached the barrier; otherwise, false.

| Improve this Doc View Source

WaitAsync(CancellationToken)

Waits for all other participants to reach the barrier.

Declaration
public ValueTask WaitAsync(CancellationToken token = null)
Parameters
Type Name Description
CancellationToken token

The token that can be used to cancel the waiting operation.

Returns
Type Description
ValueTask

The task representing asynchronous result.

| Improve this Doc View Source

WaitAsync(TimeSpan, CancellationToken)

Waits for all other participants to reach the barrier.

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

The time to wait for phase completion.

CancellationToken token

The token that can be used to cancel the waiting operation.

Returns
Type Description
ValueTask<Boolean>

true if all other participants reached the barrier; otherwise, false.

Explicit Interface Implementations

| Improve this Doc View Source

IAsyncEvent.IsSet

Declaration
bool IAsyncEvent.IsSet { get; }
Returns
Type Description
Boolean
| Improve this Doc View Source

IAsyncEvent.Reset()

Declaration
bool IAsyncEvent.Reset()
Returns
Type Description
Boolean
| Improve this Doc View Source

IAsyncEvent.Signal()

Declaration
bool IAsyncEvent.Signal()
Returns
Type Description
Boolean

Implements

IAsyncEvent
IDisposable

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)
ObjectExtensions.GetUserData<T>(T)
ObjectExtensions.IsOneOf<T>(T, IEnumerable<T>)
ObjectExtensions.IsOneOf<T>(T, T[])
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
Supported by the .NET Foundation
☀
☾