#include #include #include #include using namespace std; volatile int a = 0, b = 0; mutex m; void suma() { while (true) { m.lock(); ++a; ++b; m.unlock(); } } void resta() { while (true) { m.lock(); --a; --b; m.unlock(); } } void muestra() { while (true) { m.lock(); cout << "a = " << a << "\t b = " << b << endl; m.unlock(); this_thread::sleep_for(250ms); } } int main() { jthread t[3] = {jthread(suma), jthread(resta), jthread(muestra)}; }