を利用して時間指定するsleep
調べるのに手間取ったことその他プログラミングに関してメモを残します.
いつか始めようではいつまでも始まらなそうなので思い立った時に始めてみようと思います.
というわけで.
std::threadを使ってみていたところで,sleepさせようとしてどうしたものか迷ってしまいました.
どうにもC++のsleepは迷わずこれを使うべき,というものが無い印象.
一番汎用的なのはboost::threadにあるものに見えたものの,折角標準のstd::threadを使っているのだからこちらに合わせたい.
C++11で
sleep_for (C++11) | stops the execution of the current thread for a specified time duration (function) |
sleep_until (C++11) | stops the execution of the current thread until a specified time point (function) |
Thread support library - cppreference.com
ともにstd::this_thread名前空間内です.
とりあえず今回欲しいのはstd::this_thread::sleep_for.
std::chrono::durationを渡すとその時間だけスリープでいいみたいです.
std::this_thread::sleep_untilはtime_pointを渡すとその時間までスリープ.
std::this_thread::sleep_for(std::chrono::milliseconds(100));
まだまだリファレンスの見方が甘くてどこを見ればいいのかわからず,
闇雲にググって時間を使ってしまいます.