mscorlib(4.0.0.0) API with additions
System.Threading.Barrier Class Reference

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

Inheritance diagram for System.Threading.Barrier:
[legend]
Collaboration diagram for System.Threading.Barrier:
[legend]

Public Member Functions

 Barrier (int participantCount)
 Initializes a new instance of the T:System.Threading.Barrier class. More...
 
 Barrier (int participantCount, Action< Barrier > postPhaseAction)
 Initializes a new instance of the T:System.Threading.Barrier class. More...
 
long AddParticipant ()
 Notifies the T:System.Threading.Barrier that there will be an additional participant. More...
 
long AddParticipants (int participantCount)
 Notifies the T:System.Threading.Barrier that there will be additional participants. More...
 
void RemoveParticipant ()
 Notifies the T:System.Threading.Barrier that there will be one less participant. More...
 
void RemoveParticipants (int participantCount)
 Notifies the T:System.Threading.Barrier that there will be fewer participants. More...
 
void SignalAndWait ()
 Signals that a participant has reached the barrier and waits for all other participants to reach the barrier as well. More...
 
void SignalAndWait (CancellationToken cancellationToken)
 Signals that a participant has reached the barrier and waits for all other participants to reach the barrier, while observing a cancellation token. More...
 
bool SignalAndWait (TimeSpan timeout)
 Signals that a participant has reached the barrier and waits for all other participants to reach the barrier as well, using a T:System.TimeSpan object to measure the time interval. More...
 
bool SignalAndWait (TimeSpan timeout, CancellationToken cancellationToken)
 Signals that a participant has reached the barrier and waits for all other participants to reach the barrier as well, using a T:System.TimeSpan object to measure the time interval, while observing a cancellation token. More...
 
bool SignalAndWait (int millisecondsTimeout)
 Signals that a participant has reached the barrier and waits for all other participants to reach the barrier as well, using a 32-bit signed integer to measure the timeout. More...
 
bool SignalAndWait (int millisecondsTimeout, CancellationToken cancellationToken)
 Signals that a participant has reached the barrier and waits for all other participants to reach the barrier as well, using a 32-bit signed integer to measure the timeout, while observing a cancellation token. More...
 
void Dispose ()
 Releases all resources used by the current instance of the T:System.Threading.Barrier class. More...
 

Protected Member Functions

virtual void Dispose (bool disposing)
 Releases the unmanaged resources used by the T:System.Threading.Barrier, and optionally releases the managed resources. More...
 

Properties

int ParticipantsRemaining [get]
 Gets the number of participants in the barrier that haven’t yet signaled in the current phase. More...
 
int ParticipantCount [get]
 Gets the total number of participants in the barrier. More...
 
long CurrentPhaseNumber [get, set]
 Gets the number of the barrier's current phase. More...
 

Detailed Description

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

Definition at line 13 of file Barrier.cs.

Constructor & Destructor Documentation

◆ Barrier() [1/2]

System.Threading.Barrier.Barrier ( int  participantCount)

Initializes a new instance of the T:System.Threading.Barrier class.

Parameters
participantCountThe number of participating threads.
Exceptions
T:System.ArgumentOutOfRangeExceptionparticipantCount is less than 0 or greater than 32,767.

Definition at line 92 of file Barrier.cs.

◆ Barrier() [2/2]

System.Threading.Barrier.Barrier ( int  participantCount,
Action< Barrier postPhaseAction 
)

Initializes a new instance of the T:System.Threading.Barrier class.

Parameters
participantCountThe number of participating threads.
postPhaseActionThe T:System.Action`1 to be executed after each phase. null (Nothing in Visual Basic) may be passed to indicate no action is taken.
Exceptions
T:System.ArgumentOutOfRangeExceptionparticipantCount is less than 0 or greater than 32,767.

Definition at line 103 of file Barrier.cs.

Member Function Documentation

◆ AddParticipant()

long System.Threading.Barrier.AddParticipant ( )

Notifies the T:System.Threading.Barrier that there will be an additional participant.

Returns
The phase number of the barrier in which the new participants will first participate.
Exceptions
T:System.ObjectDisposedExceptionThe current instance has already been disposed.
T:System.InvalidOperationExceptionAdding a participant would cause the barrier's participant count to exceed 32,767.-or-The method was invoked from within a post-phase action.

Definition at line 142 of file Barrier.cs.

◆ AddParticipants()

long System.Threading.Barrier.AddParticipants ( int  participantCount)

Notifies the T:System.Threading.Barrier that there will be additional participants.

Parameters
participantCountThe number of additional participants to add to the barrier.
Returns
The phase number of the barrier in which the new participants will first participate.
Exceptions
T:System.ObjectDisposedExceptionThe current instance has already been disposed.
T:System.ArgumentOutOfRangeExceptionparticipantCount is less than 0.-or-Adding participantCount participants would cause the barrier's participant count to exceed 32,767.
T:System.InvalidOperationExceptionThe method was invoked from within a post-phase action.

Definition at line 162 of file Barrier.cs.

◆ Dispose() [1/2]

void System.Threading.Barrier.Dispose ( )

Releases all resources used by the current instance of the T:System.Threading.Barrier class.

Exceptions
T:System.InvalidOperationExceptionThe method was invoked from within a post-phase action.

Implements System.IDisposable.

Definition at line 556 of file Barrier.cs.

◆ Dispose() [2/2]

virtual void System.Threading.Barrier.Dispose ( bool  disposing)
protectedvirtual

Releases the unmanaged resources used by the T:System.Threading.Barrier, and optionally releases the managed resources.

Parameters
disposingtrue to release both managed and unmanaged resources; false to release only unmanaged resources.

Definition at line 569 of file Barrier.cs.

◆ RemoveParticipant()

void System.Threading.Barrier.RemoveParticipant ( )

Notifies the T:System.Threading.Barrier that there will be one less participant.

Exceptions
T:System.ObjectDisposedExceptionThe current instance has already been disposed.
T:System.InvalidOperationExceptionThe barrier already has 0 participants.-or-The method was invoked from within a post-phase action.

Definition at line 222 of file Barrier.cs.

◆ RemoveParticipants()

void System.Threading.Barrier.RemoveParticipants ( int  participantCount)

Notifies the T:System.Threading.Barrier that there will be fewer participants.

Parameters
participantCountThe number of additional participants to remove from the barrier.
Exceptions
T:System.ObjectDisposedExceptionThe current instance has already been disposed.
T:System.ArgumentOutOfRangeExceptionparticipantCount is less than 0.
T:System.InvalidOperationExceptionThe barrier already has 0 participants.-or-The method was invoked from within a post-phase action. -or-current participant count is less than the specified participantCount
T:System.ArgumentOutOfRangeExceptionThe total participant count is less than the specified participantCount

Definition at line 235 of file Barrier.cs.

◆ SignalAndWait() [1/6]

void System.Threading.Barrier.SignalAndWait ( )

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

Exceptions
T:System.ObjectDisposedExceptionThe current instance has already been disposed.
T:System.InvalidOperationExceptionThe method was invoked from within a post-phase action, the barrier currently has 0 participants, or the barrier is signaled by more threads than are registered as participants.
T:System.Threading.BarrierPostPhaseExceptionIf an exception is thrown from the post phase action of a Barrier after all participating threads have called SignalAndWait, the exception will be wrapped in a BarrierPostPhaseException and be thrown on all participating threads.

Definition at line 282 of file Barrier.cs.

◆ SignalAndWait() [2/6]

void System.Threading.Barrier.SignalAndWait ( CancellationToken  cancellationToken)

Signals that a participant has reached the barrier and waits for all other participants to reach the barrier, while observing a cancellation token.

Parameters
cancellationTokenThe T:System.Threading.CancellationToken to observe.
Exceptions
T:System.OperationCanceledExceptioncancellationToken has been canceled.
T:System.ObjectDisposedExceptionThe current instance has already been disposed.
T:System.InvalidOperationExceptionThe method was invoked from within a post-phase action, the barrier currently has 0 participants, or the barrier is signaled by more threads than are registered as participants.

Definition at line 294 of file Barrier.cs.

◆ SignalAndWait() [3/6]

bool System.Threading.Barrier.SignalAndWait ( TimeSpan  timeout)

Signals that a participant has reached the barrier and waits for all other participants to reach the barrier as well, using a T:System.TimeSpan object to measure the time interval.

Parameters
timeoutA T:System.TimeSpan that represents the number of milliseconds to wait, or a T:System.TimeSpan that represents -1 milliseconds to wait indefinitely.
Returns
true if all other participants reached the barrier; otherwise, false.
Exceptions
T:System.ObjectDisposedExceptionThe current instance has already been disposed.
T:System.ArgumentOutOfRangeExceptiontimeout is a negative number other than -1 milliseconds, which represents an infinite time-out, or it is greater than 32,767.
T:System.InvalidOperationExceptionThe method was invoked from within a post-phase action, the barrier currently has 0 participants, or the barrier is signaled by more threads than are registered as participants.

Definition at line 307 of file Barrier.cs.

◆ SignalAndWait() [4/6]

bool System.Threading.Barrier.SignalAndWait ( TimeSpan  timeout,
CancellationToken  cancellationToken 
)

Signals that a participant has reached the barrier and waits for all other participants to reach the barrier as well, using a T:System.TimeSpan object to measure the time interval, while observing a cancellation token.

Parameters
timeoutA T:System.TimeSpan that represents the number of milliseconds to wait, or a T:System.TimeSpan that represents -1 milliseconds to wait indefinitely.
cancellationTokenThe T:System.Threading.CancellationToken to observe.
Returns
true if all other participants reached the barrier; otherwise, false.
Exceptions
T:System.OperationCanceledExceptioncancellationToken has been canceled.
T:System.ObjectDisposedExceptionThe current instance has already been disposed.
T:System.ArgumentOutOfRangeExceptiontimeout is a negative number other than -1 milliseconds, which represents an infinite time-out.
T:System.InvalidOperationExceptionThe method was invoked from within a post-phase action, the barrier currently has 0 participants, or the barrier is signaled by more threads than are registered as participants.

Definition at line 323 of file Barrier.cs.

◆ SignalAndWait() [5/6]

bool System.Threading.Barrier.SignalAndWait ( int  millisecondsTimeout)

Signals that a participant has reached the barrier and waits for all other participants to reach the barrier as well, using a 32-bit signed integer to measure the timeout.

Parameters
millisecondsTimeoutThe number of milliseconds to wait, or F:System.Threading.Timeout.Infinite(-1) to wait indefinitely.
Returns
if all participants reached the barrier within the specified time; otherwise false.
Exceptions
T:System.ObjectDisposedExceptionThe current instance has already been disposed.
T:System.ArgumentOutOfRangeExceptionmillisecondsTimeout is a negative number other than -1, which represents an infinite time-out.
T:System.InvalidOperationExceptionThe method was invoked from within a post-phase action, the barrier currently has 0 participants, or the barrier is signaled by more threads than are registered as participants.
T:System.Threading.BarrierPostPhaseExceptionIf an exception is thrown from the post phase action of a Barrier after all participating threads have called SignalAndWait, the exception will be wrapped in a BarrierPostPhaseException and be thrown on all participating threads.

Definition at line 342 of file Barrier.cs.

◆ SignalAndWait() [6/6]

bool System.Threading.Barrier.SignalAndWait ( int  millisecondsTimeout,
CancellationToken  cancellationToken 
)

Signals that a participant has reached the barrier and waits for all other participants to reach the barrier as well, using a 32-bit signed integer to measure the timeout, while observing a cancellation token.

Parameters
millisecondsTimeoutThe number of milliseconds to wait, or F:System.Threading.Timeout.Infinite(-1) to wait indefinitely.
cancellationTokenThe T:System.Threading.CancellationToken to observe.
Returns
if all participants reached the barrier within the specified time; otherwise false
Exceptions
T:System.OperationCanceledExceptioncancellationToken has been canceled.
T:System.ObjectDisposedExceptionThe current instance has already been disposed.
T:System.ArgumentOutOfRangeExceptionmillisecondsTimeout is a negative number other than -1, which represents an infinite time-out.
T:System.InvalidOperationExceptionThe method was invoked from within a post-phase action, the barrier currently has 0 participants, or the barrier is signaled by more threads than are registered as participants.

Definition at line 358 of file Barrier.cs.

Property Documentation

◆ CurrentPhaseNumber

long System.Threading.Barrier.CurrentPhaseNumber
getset

Gets the number of the barrier's current phase.

Returns
Returns the number of the barrier's current phase.

Definition at line 75 of file Barrier.cs.

◆ ParticipantCount

int System.Threading.Barrier.ParticipantCount
get

Gets the total number of participants in the barrier.

Returns
Returns the total number of participants in the barrier.

Definition at line 63 of file Barrier.cs.

◆ ParticipantsRemaining

int System.Threading.Barrier.ParticipantsRemaining
get

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

Returns
Returns the number of participants in the barrier that haven’t yet signaled in the current phase.

Definition at line 48 of file Barrier.cs.


The documentation for this class was generated from the following file: