New adopted paper: N3659, Shared Locking in C++ -- Howard Hinnant, Detlef Vollmann, Hans Boehm

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


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:

  1. Exclusive, using lock(), or
  2. Shared, using lock_shared().

... The recommended pattern for locking a shared_mutex in shared ownership mode is not to call m.lock_shared() directly, but to use shared_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.

Comments (1)

0 0

Tomasz KamiƄski said on Apr 23, 2013 03:03 PM:

Why was upgrade locking facilities removed from the proposal?