Yes, I can use Sleep () on Windows or pause () on POSIX and continue. But how can I only sleep using C ++ 11? I thought there was a way that connects a thread call using std :: this_thread, but std :: this_thread does not have a join () method, unlike pthread functions. Not to mention the fact that we cannot process signals with C ++ 11, and I know how to repeat sleep forever, as shown below:
while(true) std::this_thread::sleep_for(std::chrono::seconds(1));
However, as you can see, this is far from elegant. This code still consumes CPU time. The planner must take care of this process. I could also use a conditional variable or promise, but then again it takes up some memory or will not work on a specific OS (it would choose an exception to avoid a deadlock).
Perhaps this could be the equivalent of Sleep (INFINITE) Windows:
while(true) std::this_thread::sleep_for(std::chrono::hours::max());
But many say that is impractical.
Can anyone think of a brilliant path?
source share