xtd 0.2.0
barrier_simple.cpp

Shows how to use xtd::threading::barrier class.

#include <xtd/threading/barrier>
#include <xtd/threading/thread_pool>
#include <xtd/console>
#include <xtd/startup>
using namespace xtd;
using namespace xtd::threading;
namespace barrier_example {
class program {
public:
static void main() {
for (auto index = 0; index < task_count; ++index)
}
private:
static void perform_phase() {
console::write_line("Thread {} is performing its work", thread::current_thread().managed_thread_id());
console::write_line("Thread {} compelted the phase", thread::current_thread().managed_thread_id());
}
static constexpr int task_count = 3;
inline static threading::barrier barrier {task_count};
};
}
startup_(barrier_example::program::main);
// This example produces output similar to the following:
//
// Thread 9 is performing its work
// Thread 11 is performing its work
// Thread 8 is performing its work
// Thread 11 compelted the phase
// Thread 8 compelted the phase
// Thread 9 compelted the phase
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
Enables multiple tasks to cooperatively work on an algorithm in parallel through multiple phases.
Definition barrier.hpp:31
void signal_and_wait()
Signals that a participant has reached the barrier and waits for all other participants to reach the ...
static bool queue_user_work_item(const wait_callback &callback)
Queues a method for execution. The method executes when a thread pool thread becomes available.
static thread & current_thread() noexcept
Gets the currently running thread.
#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
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8