Enables multiple tasks to cooperatively work on an algorithm in parallel through multiple phases.
- Header
#include <xtd/threading/barrier>
- Namespace
- xtd::threading
- Library
- xtd.core
- Examples
#include <xtd/threading/barrier>
#include <xtd/threading/interlocked>
#include <xtd/threading/thread_pool>
#include <xtd/console>
#include <xtd/startup>
namespace barrier_example {
class program {
public:
static void main() {
auto count = 0;
console::write_line(
"Post-Phase action: count={0}, phase={1}", count, b.current_phase_number());
}}};
try {
}
};
for (auto index = 0; index < 4; ++index)
}
};
}
startup_(barrier_example::program::main);
|
| object ()=default |
| Create a new instance of the ultimate base class object. More...
|
|
bool | equals (const object &obj) const noexcept |
| Determines whether the specified object is equal to the current object. More...
|
|
virtual size_t | get_hash_code () const noexcept |
| Serves as a hash function for a particular type. More...
|
|
virtual type_object | get_type () const noexcept |
| Gets the type of the current instance. More...
|
|
template<typename object_t > |
std::unique_ptr< object_t > | memberwise_clone () const noexcept |
| Creates a shallow copy of the current object. More...
|
|
virtual xtd::ustring | to_string () const noexcept |
| Returns a sxd::ustring that represents the current object. More...
|
|
static bool | equals (const object &object_a, const object &object_b) noexcept |
| Determines whether the specified object instances are considered equal. More...
|
|
static bool | reference_equals (const object &object_a, const object &object_b) noexcept |
| Determines whether the specified object instances are the same instance. More...
|
|
◆ post_phase_action
◆ barrier() [1/2]
xtd::threading::barrier::barrier |
( |
int32 |
participant_count | ) |
|
|
explicit |
Initializes a new instance of the xtd::threading::barrier class.
- Parameters
-
participant_count | The number of participating threads. |
- Exceptions
-
◆ barrier() [2/2]
Initializes a new instance of the xtd::threading::barrier class.
- Parameters
-
participant_count | The number of participating threads. |
post_phase_action | The xtd::action< barrier& > to be executed after each phase. Empty may be passed to indicate no action is taken. |
- Exceptions
-
◆ add_participant()
int32 xtd::threading::barrier::add_participant |
( |
| ) |
|
Notifies the xtd::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
-
◆ add_participants()
int32 xtd::threading::barrier::add_participants |
( |
int32 |
participant_count | ) |
|
Notifies the xtd::threading::barrier that there will be additional participants.
- Parameters
-
participant_count | The 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
-
◆ close()
void xtd::threading::barrier::close |
( |
| ) |
|
◆ current_phase_number()
int32 xtd::threading::barrier::current_phase_number |
( |
| ) |
const |
Gets the number of the barrier's current phase.
- Returns
- Returns the number of the barrier's current phase.
- Exceptions
-
◆ participant_count()
int32 xtd::threading::barrier::participant_count |
( |
| ) |
const |
Gets the total number of participants in the barrier.
- Returns
- Returns the total number of participants in the barrier.
- Exceptions
-
◆ participants_remaining()
int32 xtd::threading::barrier::participants_remaining |
( |
| ) |
const |
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.
- Exceptions
-
◆ remove_participant()
int32 xtd::threading::barrier::remove_participant |
( |
| ) |
|
Notifies the Barrier that there will be one less participant.
- Returns
- The phase number of the barrier in which the new participants will first participate.
- Exceptions
-
◆ remove_participants()
int32 xtd::threading::barrier::remove_participants |
( |
int32 |
participant_count | ) |
|
Notifies the Barrier that there will be fewer participants.
- Parameters
-
participant_count | The number of additional participants to remove from the barrier. |
- Returns
- The phase number of the barrier in which the new participants will first participate.
- Exceptions
-
◆ signal_and_wait() [1/6]
void xtd::threading::barrier::signal_and_wait |
( |
| ) |
|
Signals that a participant has reached the barrier and waits for all other participants to reach the barrier as well.
- Exceptions
-
◆ signal_and_wait() [2/6]
bool xtd::threading::barrier::signal_and_wait |
( |
int32 |
milliseconds_timeout | ) |
|
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
-
- Returns
- true if all participants reached the barrier within the specified time; otherwise false.
- Exceptions
-
◆ signal_and_wait() [3/6]
bool xtd::threading::barrier::signal_and_wait |
( |
const cancellation_token & |
cancellation_token | ) |
|
Signals that a participant has reached the barrier and waits for all other participants to reach the barrier, while observing a cancellation token.
- Parameters
-
- Returns
- true if all participants reached the barrier within the specified time; otherwise false. xtd::operation_canceled_exception cancellation_token has been canceled.
- Exceptions
-
◆ signal_and_wait() [4/6]
bool xtd::threading::barrier::signal_and_wait |
( |
const time_span & |
timeout | ) |
|
Signals that a participant has reached the barrier and waits for all other participants to reach the barrier as well, using a xtd::time_span object to measure the time interval.
- Parameters
-
timout | A xtd::time_span that represents the number of milliseconds to wait, or a xtd::time_span that represents -1 milliseconds to wait indefinitely. |
- Returns
- true if all participants reached the barrier within the specified time; otherwise false.
- Exceptions
-
◆ signal_and_wait() [5/6]
bool xtd::threading::barrier::signal_and_wait |
( |
int32 |
milliseconds_timeout, |
|
|
const cancellation_token & |
cancellation_token |
|
) |
| |
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
-
- Returns
- true if all participants reached the barrier within the specified time; otherwise false.
- Exceptions
-
◆ signal_and_wait() [6/6]
Signals that a participant has reached the barrier and waits for all other participants to reach the barrier as well, using a xtd::time_span object to measure the time interval, while observing a cancellation token.
- Parameters
-
- Returns
- true if all participants reached the barrier within the specified time; otherwise false.
- Exceptions
-
The documentation for this class was generated from the following file: