Named manual-reset event synchronization primitive example
#include <iostream>
#include <thread>
#include <vector>
int main(int argc, char** argv)
{
std::string help = "Please enter '!' to signal the named manual-reset event (several processes support). Enter '0' to exit...";
std::cout << help << std::endl;
int concurrency = 8;
std::vector<std::thread> threads;
for (int thread = 0; thread < concurrency; ++thread)
{
threads.emplace_back([thread]()
{
std::cout << "Thread " << thread << " initialized!" << std::endl;
std::cout << "Thread " << thread << " waiting for the event!" << std::endl;
std::cout << "Thread " << thread << " signaled!" << std::endl;
});
}
std::string line;
while (getline(std::cin, line))
{
if (line == "!")
{
std::cout << "Signal event!" << std::endl;
}
else if (line == "0")
break;
else
std::cout << help << std::endl;
}
for (auto& thread : threads)
thread.join();
return 0;
}
Named manual-reset event synchronization primitive.
void Signal()
Signal one of waiting thread about event occurred.
void Wait()
Try to wait the event with block.
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.
Named manual-reset event synchronization primitive definition.