How Does C++ Read-Write Lock (shared_mutex) Work?

How Does C++ Read-Write Lock (shared_mutex) Work?

Sometimes, we encounter a situation where: “many reads, very few writes.” For example, configuration, status information, coordinate parameters, etc. If all threads use <span>std::mutex</span>, then read operations will queue up, wasting performance, which is unfortunate 😅 To solve this problem, C++17 introduced a smarter lock 🔒: “std::shared_mutex”. Why is it called a Read-Write Lock? You … Read more