void* handle1(void* arg){ mtx.lock(); std::cout<<"thread1 before add:"<<cnt<<std::endl; cnt++; std::cout<<"thread1 after add: "<<cnt<<std::endl; mtx.unlock(); sleep(2); }
void* handle2(void* arg){ while(1){ mtx.lock(); std::cout<<"thread2 before add:"<<cnt<<std::endl; cnt++; std::cout<<"thread2 after add: "<<cnt<<std::endl; mtx.unlock(); sleep(2); } }