#include <iostream>
#include <condition_variable>
#include <thread>
#include <chrono>

std::condition_variable cv;
std::mutex cv_m;
int i=0;

#define WAIT

void waits1()
{
    std::unique_lock<std::mutex> lk(cv_m);
    std::cerr << "In waits1... \n";
    std::this_thread::sleep_for(std::chrono::seconds(1));
#ifdef WAIT
    cv.wait(lk, []{return i == 1;});
#endif
    std::cerr << "waits1 done ... \n";
}

void waits2()
{
    std::unique_lock<std::mutex> lk(cv_m);
    std::cerr << "In waits2... \n";
    std::this_thread::sleep_for(std::chrono::seconds(1));
#ifdef WAIT
    cv.wait(lk, []{return i == 2;});
#endif
    std::cerr << "waits2 done ... \n";
}

int main()
{
    std::thread 
        t2(waits2),
        t1(waits1);
    t1.join(); 
    t2.join(); 
}