multithreading - C++ threads: How do I stop two different functions from being called at the same time? -
i'm new c++ threads , i'm using boost threading. trying figure out how stop 2 functions being called @ same time.
void function1(){ //some task } void function2(){ //some other task } //both tasks can not run @ same time
how stop function 1 , function 2 running @ same time?
you should use synchronization mechanism std::mutex
shared between them:
std::mutex m; void function1() { std::lock(m); } void function2(){ std::lock(m); }
Comments
Post a Comment