Shows how to use xtd::threading::manual_reset_event class.
#include <xtd/threading/manual_reset_event>
#include <xtd/threading/thread>
#include <xtd/console>
#include <xtd/startup>
namespace manual_reset_event_example {
class program {
public:
static void main() {
for(
auto i = 0;
i <= 2; ++
i) {
threads.emplace_back(thread_proc);
threads.back().start();
}
"\nto release all the threads.\n");
mre.set();
"\ndo not block. Press Enter to show this.\n");
for(
auto i = 3;
i <= 4; ++
i) {
threads.emplace_back(thread_proc);
threads.back().start();
}
"\nwhen they call WaitOne().\n");
mre.reset();
threads.emplace_back(thread_proc);
threads.back().name("Thread_5");
threads.back().start();
mre.set();
}
private:
inline static std::vector<thread> threads = std::vector<thread>(4);
static void thread_proc() {
mre.wait_one();
}
};
}
startup_(manual_reset_event_example::program::main);