Note: This paper was adopted into draft C++14 on Saturday at the Bristol UK ISO C++ meeting.
A new WG21 paper is available. A copy is linked below, and the paper will also appear in the next normal WG21 mailing. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.
Document number: N3659
Date: 2013-04-19
Shared locking in C++ (a.k.a. reader/writer locks)
by Howard Hinnant, Detlef Vollmann, Hans Boehm
Excerpt:
N3568 was presented at the Spring 2013 meeting in Bristol to SG1 (Concurrency and Parallelism). The decision was to bring
shared_mutex
only forward for C++14. Also the specification should allow for spurious failures.
From N3568:
This proposal adds functionality to allow clients to easily code the well-known multiple-readers / single-writer locking pattern. ...
... a
shared_mutex
can be locked in one of two ownership modes:
- Exclusive, using
lock()
, or- Shared, using
lock_shared()
.... The recommended pattern for locking a
shared_mutex
in shared ownership mode is not to callm.lock_shared()
directly, but to useshared_lock<shared_mutex>
:shared_mutex mut; ... void foo() { shared_lock<shared_mutex> _(mut); // mut lock_shared'd here // ... } // mut.unlock_shared() called here
Add a Comment
Comments are closed.