1. std::mutex + std::condition_variable
std::mutex mutex;
std::condition_variable cv;
// wait
std::unique_lock<std::mutex> lk(mutex);
cv.wait(lk);
// notify
std::lock_guard<std::mutex> lg(mutex);
cv.notify_all();
2. std::future/std::promise
这种方式只适合同步一次。
std::promise<bool> prom;
// wait
prom.get_future().get();
// notify
prom.set_value(true);
3. posix - semphore
sem_t sem;
sem_init(&sem, 0, 0);
// wait
sem_wait(&sem);
// notify
sem_post(&sem);