c++11 mutex/atomic
mutex/atomic c++ basic data struct is not thread-safe, only multithreading read and no write is safe. mutex/atomic tool can solve data race, but if you use them incorrect, it will cause deadlock. mutex basic mutex basic mutex is std::mutex object, very simple rule: call member function lock to lock it, call unlock to unlock it. but you can not lock it when it locked, also not unlock it when it not locked, or it will cause deadlock. std::mutex mtx; mtx.lock(); // ... mtx.unlock(); recursive mutex recursive mutex is std::recursive_mutex object, difference from basic mutex, it will not cause