Title
Mutex type overspecified
Status
lewg
Section
[thread.mutex.requirements]
Submitter
Pete Becker

Created on 2008-12-05.00:00:00 last changed 95 months ago

Messages

Date: 2017-03-15.00:00:00

[ 2017-03-01, Kona ]

SG1: Agreement that we need a paper.

Date: 2010-10-21.18:28:33

[ Post Summit Anthony adds: ]

Section [thread.mutex.requirements] conflates the requirements on a generic Mutex type (including user-supplied mutexes) with the requirements placed on the standard-supplied mutex types in an attempt to group everything together and save space.

When applying concepts to chapter 30, I suggest that the concepts Lockable and TimedLockable embody the requirements for *use* of a mutex type as required by unique_lock/lock_guard/condition_variable_any. These should be relaxed as Pete describes in the issue. The existing words in [thread.mutex.requirements] are requirements on all of std::mutex, std::timed_mutex, std::recursive_mutex and std::recursive_timed_mutex, and should be rephrased as such.

Date: 2010-10-21.18:28:33

[ Summit: ]

Move to open. Related to conceptualization and should probably be tackled as part of that.

  • The intention is not only to place a constraint on what types such as lock_guard may do with mutex types, but on what any code, including user code, may do with mutex types. Thus the constraints as they are apply to the mutex types themselves, not the current users of mutex types in the standard.
  • This is a low priority issue; the wording as it is may be overly restrictive but this may not be a real issue.
Date: 2008-12-05.00:00:00

Duplicate: 961

[thread.mutex.requirements] describes the requirements for a type to be a "Mutex type". A Mutex type can be used as the template argument for the Lock type that's passed to condition_variable_any::wait (although Lock seems like the wrong name here, since Lock is given a different formal meaning in [thread.lock]) and, although the WD doesn't quite say so, as the template argument for lock_guard and unique_lock.

The requirements for a Mutex type include:

  • m.lock() shall be well-formed and have [described] semantics, including a return type of void.
  • m.try_lock() shall be well-formed and have [described] semantics, including a return type of bool.
  • m.unlock() shall be well-formed and have [described] semantics, including a return type of void.

Also, a Mutex type "shall not be copyable nor movable".

The latter requirement seems completely irrelevant, and the three requirements on return types are tighter than they need to be. For example, there's no reason that lock_guard can't be instantiated with a type that's copyable. The rule is, in fact, that lock_guard, etc. won't try to copy objects of that type. That's a constraint on locks, not on mutexes. Similarly, the requirements for void return types are unnecessary; the rule is, in fact, that lock_guard, etc. won't use any returned value. And with the return type of bool, the requirement should be that the return type is convertible to bool.

History
Date User Action Args
2017-03-01 18:09:34adminsetmessages: + msg9024
2014-11-24 15:11:58adminsetstatus: nad future -> lewg
2010-10-21 18:28:33adminsetmessages: + msg4454
2010-10-21 18:28:33adminsetmessages: + msg4453
2008-12-05 00:00:00admincreate