N3891: A proposal to rename shared_mutex to shared_timed_mutex

Gor Nishanov, Herb Sutter {gorn,hsutter}@microsoft.com

2014-01-14

Table of Contents

Introduction.. 1

Background.. 1

Changes compared to N3797.. 2

Proposed Wording (s/shared_mutex/shared_timed_mutex/g). 2

Acknowledgements. 3

 

Introduction

We propose to rename shared_mutex to shared_timed_mutex:

(a) for consistency with the other mutexes (fixing naming inconsistency);

(b) to leave room for a shared_mutex which can be more efficient on some platforms than shared_timed_ mutex.

Background

Prior to this proposal shared_mutex was not following the precedent set by timed_mutex and recursive_timed_mutex, by not including timed into its name.

Non-timed mutexes

Timed mutexes

std::mutex

std::timed_mutex

std::recursive_mutex

std::recursive_timed_mutex

 

std::shared_mutex

 

With this proposal, we fix this naming inconsistency and leave room for the natural name of a shared_mutex that does not have to satisfy a timed mutex requirement.

Non-timed mutexes

Timed mutexes

std::mutex

std::timed_mutex

std::recursive_mutex

std::recursive_timed_mutex

std::shared_mutex (can be proposed later)

std::shared_timed_mutex

 

There is a performance motivation for a non-timed shared_mutex. On Windows, it can be implemented in terms of slim reader/writer locks that have superior performance on some benchmarks to even simple exclusive locks. See: Performance Comparison on Reader-Writer Locks and MSDN Mag: Synchronization Primitives New To Windows Vista.

Changes compared to N3797

This paper only includes the proposed wording due to rename. For background please refer to N3659.

Proposed Wording (s/shared_mutex/shared_timed_mutex/g)

Modify shared_mutex synopsis of 30.4 [thread.mutex] as follows:

Header <shared_mutex> synopsis

 

namespace std {

  class shared_timed_mutex;

  template <class Mutex> class shared_lock;

  template <class Mutex>

  void swap(shared_lock<Mutex>& x, shared_lock<Mutex>& y) noexcept;

}

 

Modify 30.4.1.2 [thread.mutex.requirements.mutex] as follows:

 

30.4.1.2 Mutex types [thread.mutex.requirements.mutex]

1 The mutex types are the standard library types std::mutex, std::recursive_mutex, std::timed_mutex, std::recursive_timed_mutex, and std::shared_timed_mutex. They shall meet the requirements set out in this section. In this description, m denotes an object of a mutex type.

 

Modify 30.4.1.3 [thread.timedmutex.requirements] as follows:

 

30.4.1.3 Timed mutex types [thread.timedmutex.requirements]

1 The timed mutex types are the standard library types std::timed_mutex, std::recursive_timed_mutex, and std::shared_timed_mutex.

 

Modify 30.4.1.4 [thread.sharedmutex.requirements] as follows:

30.4.1.4 Shared timed mutex types [thread.sharedtimedmutex.requirements]

The standard library type std::shared_timed_mutex is a shared timed mutex type. Shared timed mutex types shall meet the requirements of timed mutex types ([thread.timedmutex.requirements]), and additionally shall meet the requirements set out below. In this description, m denotes an object of a mutex type, rel_type denotes an object of an instantiation of duration (20.11.5), and abs_time denotes an object of an instantiation of time_point (20.11.6).

Modify 30.4.1.4.1 [thread.sharedmutex.requirements] as follows:

 

30.4.1.4.1 Class shared_timed_mutex [thread.sharedtimedmutex.class]

namespace std {

   class shared_timed_mutex {

   public:

       shared_timed_mutex();

      ~shared_timed_mutex();

       shared_timed_mutex(const shared_timed_mutex&) = delete;

       shared_timed_mutex& operator=(const shared_timed_mutex&) = delete;

 

1 The class shared_timed_mutex provides a non-recursive mutex with shared ownership semantics.

2 The class shared_timed_mutex shall satisfy all of the SharedTimedMutex requirements (30.4.1.4). It shall be a standard layout class (Clause 9).

3 The behavior of a program is undefined if:

— it destroys a shared_timed_mutex object owned by any thread,

— a thread attempts to recursively gain any ownership of a shared_timed_mutex.

             — a thread terminates while possessing any ownership of a shared_timed_mutex.

 

Acknowledgements

Thanks to Artur Laksberg, Gabriel Dos Reis, James McNellis and Stephan T. Lavavej for their feedback and review.