「起こす」は「1人だけ起こす (notify_one)」と「みんな起こす (notify_all)」の2種類。 「寝る」には「永遠に寝る (wait)」「一定時間寝る (wait_for)」「ある時刻まで寝る (wait_until)」の3種類がある。 片方のスレッドが condition_variable を介して眠り、それをもう片方のスレッドが起こすという簡単なサンプルを見てみよう。 #include <iostream> #include <thread> #include <condition_variable> #include <mutex> #include <chrono> int main() { std::mutex mtx; // wait で必要(とりあえず無視) std::condition_variable cv; // これを介して睡眠をコントロールする //
