C++ Mutexes std::scoped_lock (C++ 17)

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

std::scoped_lock provides RAII style semantics for owning one more mutexes, combined with the lock avoidance algorithms used by std::lock. When std::scoped_lock is destroyed, mutexes are released in the reverse order from which they where acquired.

{
    std::scoped_lock lock{_mutex1,_mutex2};
    //do something
}


Got any C++ Question?