The difference between lock_guard and unique_lock in c++11_The difference between lock_guard and unique_lock_GoKu~’s Blog
Analysis of the use of lock_guard and unique_lock in c++11 Lock Locks are used to prevent data races when multiple threads access the same resource, ensuring Consistent access to data. Multithreading is originally to improve efficiency and response speed, but the use of locks limits the parallel execution of multithreading, which will reduce efficiency, but in order to ensure correct data, locks have to be used, and they are entangled like this. As a c++ developer who prioritizes efficiency, many people talk about locking color. Although there are many lock-free technologies applied to the project, it is still necessary to have a basic understanding of the lock technology. This article mainly discusses two kinds of locks in c++11: lock_guard and unique_lock. Combined with locks to synchronize the use of condition variables between threads, please refer to the condition variable condition variable. lock_guard lock_guard is a mutex wrapper that provides a convenient RAII (Resource acquisition is initialization) style mechanism to own a mutex for the duration of a scoped block. When a lock_guard object is created, it attempts to take ownership of the mutex provided to it. When the control flow leaves the scope of the lock_guard object, the lock_guard destroys…