#include <xtd/xtd>
namespace barrier_example {
class program {
public:
static void main() {
auto count = 0;
auto barrier = threading::barrier {3, action<threading::barrier&> {[&](threading::barrier& b) {
console::write_line("Post-Phase action: count={0}, phase={1}", count, b.current_phase_number());
if (b.current_phase_number() == 2) throw system_exception("D'oh!");
}}};
barrier.add_participants(2);
barrier.remove_participant();
auto action = [&] {
interlocked::increment(count);
barrier.signal_and_wait();
interlocked::increment(count);
barrier.signal_and_wait();
interlocked::increment(count);
try {
barrier.signal_and_wait();
} catch (const barrier_post_phase_exception& bppe) {
console::write_line("Caught barrier_post_phase_exception: {0}", bppe.message());
}
interlocked::increment(count);
barrier.signal_and_wait();
};
for (auto index = 0; index < 4; ++index)
thread_pool::queue_user_work_item(action);
thread::join_all();
barrier.close();
}
};
}
startup_(barrier_example::program::main);
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:168