Shows how to use xtd::threading::auto_reset_event class.
#include <xtd/threading/auto_reset_event>
#include <xtd/threading/thread>
#include <xtd/console>
#include <xtd/startup>
namespace auto_reset_event_example {
class program {
public:
static auto main() {
"The threads wait on auto_reset_event #1, which was created\r\n"
"in the signaled state, so the first thread is released.\r\n"
"This puts auto_reset_event #1 into the unsignaled state.");
for (auto index = 1; index < 4; ++index) {
threads.emplace_back(thread_proc);
threads.back().start();
}
for (auto index = 0; index < 2; ++index) {
event_1.set();
}
for (
int i = 0;
i < 3;
i++) {
event_2.set();
}
}
static void thread_proc() {
event_1.wait_one();
event_2.wait_one();
}
private:
inline static std::vector<thread> threads = std::vector<thread>(4);
};
}
startup_(auto_reset_event_example::program::main);