xtd 0.2.0
Loading...
Searching...
No Matches
countdown_event.cpp

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

#include <xtd/threading/countdown_event>
#include <xtd/threading/thread>
#include <xtd/console>
#include <xtd/startup>
using namespace xtd;
using namespace xtd::threading;
namespace monitor_lock_example {
class program {
public:
static void main() {
auto thread_proc = [&] {
console::write_line("Thread {} signals countdown_event", thread::current_thread().managed_thread_id());
};
for (auto i = 0; i < 5; ++i)
thread::start_new(thread_proc);
console::write_line("All threads have signaled countdown_event");
}
};
}
startup_(monitor_lock_example::program::main);
// This example produces output similar to the following:
//
// Thread 2 signals countdown_event
// Thread 3 signals countdown_event
// Thread 4 signals countdown_event
// Thread 6 signals countdown_event
// Thread 5 signals countdown_event
// All threads have signaled countdown_event
Represents a synchronization primitive that is signaled when its count reaches zero.
Definition countdown_event.h:28
void wait()
Blocks the current thread until the xtd::threading::countdown_event is set.
bool signal()
Registers a signal with the xtd::threading::countdown_event, decrementing the value of xtd::threading...
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.h:166
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.h:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10