#include #include #include #include #include #define NUM_THREADS 4 std::condition_variable cond; std::mutex mx; int started = 0; void do_thread () { std::unique_lock lock(mx); std::cout << "Start thread " << started << std::endl; if(++started >= NUM_THREADS) cond.notify_all(); else cond.wait(lock); } int main () { std::vector vec; for (int i = 0; i < NUM_THREADS; ++i) vec.emplace_back(&do_thread); for (int i = 0; i < NUM_THREADS; ++i) vec[i].join(); vec.clear(); return 0; }