Auto-reset event synchronization primitive example
#include <iostream>
#include <thread>
#include <vector>
int main(int argc, char** argv)
{
int concurrency = 8;
std::vector<std::thread> threads;
for (int thread = 0; thread < concurrency; ++thread)
{
threads.emplace_back([&event, thread]()
{
std::cout << "Thread " << thread << " initialized!" << std::endl;
std::cout << "Thread " << thread << " waiting for the event!" << std::endl;
event.Wait();
std::cout << "Thread " << thread << " signaled!" << std::endl;
});
}
for (int thread = 0; thread < concurrency; ++thread)
{
std::cout << "Signal event!" << std::endl;
event.Signal();
}
for (auto& thread : threads)
thread.join();
return 0;
}
Auto-reset event synchronization primitive.
static void SleepFor(const Timespan ×pan) noexcept
Sleep the current thread for the given timespan.
int64_t milliseconds() const noexcept
Get total milliseconds of the current timespan.
Auto-reset event synchronization primitive definition.