How to make shared_lock or upgrade_lock in standard C ++ 11?

I have lost a lot from the new std::shared_lock template std::shared_lock . In Boost.Thread, there is boost::shared_lock , even boost::upgrade_lock exists.

Why is it that there is no std :: shared_lock and std::unique_lock in C ++ 11?
How can I get a similar behavior like boost::shared_lock , but in pure C ++ 11?

I thought to use boost::shared_lock<std::mutex> , but that doesn't make much sense, since std::mutex does not have a lock_shared() member. And also there are no such as std::shared_mutex .

+6
source share
1 answer

Howard's suggestion for std::shared_mutex was rejected for C ++ 11 due to lack of time to properly consider it. He proposed this again for C ++ 17, and this is discussed at a meeting in Portland this week.

At the same time, if you can use Boost, then you can also; there will be no new features for standardization.

Nevertheless, it is worth checking that using shared_mutex really useful - in many cases it does not provide the expected performance gain due to competition on the mutex itself.

+11
source

Source: https://habr.com/ru/post/928023/


All Articles