c++ - Is there a built-in function to make part of a thread not run concurrently? -
so question is, there build-in function create part of thread not run concurrently in c++ pthreads, or have create myself token or that.
what want mutual exclusion, or mutex. standard c++, no pthreads needed. header called <mutex>
, , type std::mutex
.
one trick how lock it: std::lock_guard<mutex> lock(yoursshmutex)
- lock object keeps mutex locked while exists, lock_guard::~lock_guard
unlocks it. prevents forgetting unlock mutex when done.
c++ pthreads
No comments:
Post a Comment