#include #include #include std::mutex mx; int i; void thrfunc(); int main(void) { i=0; std::thread thr1(thrfunc),thr2(thrfunc); thr1.join(); thr2.join(); return 0; } void thrfunc() { mx.lock(); i++; std::cout << std::this_thread::get_id() << " i: " << i << std::endl; mx.unlock(); }