7

I am missing very much from the new standard the std::shared_lock template class. In Boost.Thread there is boost::shared_lock, even boost::upgrade_lock exists.

Why is that, there is no std::shared_lock and std::unique_lock in C++11?
How is it possible to acquire a similar behavior as boost::shared_lock has, but in pure C++11?

I was thinking to use boost::shared_lock<std::mutex>, but this doesn't have so much sense, since std::mutex does not have a lock_shared() member. And also, there is no such as std::shared_mutex.

ildjarn
  • 62,044
  • 9
  • 127
  • 211
Gabor Marton
  • 2,039
  • 2
  • 22
  • 33

1 Answers1

11

Howard's proposal for std::shared_mutex was turned down for C++11 due to lack of time to consider it properly. He's proposed it again for C++17, and it's being discussed at the meeting in Portland this week.

In the mean time, if you can use Boost then you may as well; there won't be any new functionality for it being standardized.

That said, it's worth checking that using shared_mutex is actually of benefit --- in many cases it doesn't provide the hoped-for performance gains due to contention on the mutex itself.

Anthony Williams
  • 66,628
  • 14
  • 133
  • 155
  • Thanks for you answer Anthony. Since than I did some digging and find this discussion about Howard's proposal: http://permalink.gmane.org/gmane.comp.lib.boost.devel/211180 – Gabor Marton Oct 19 '12 at 13:38