This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofResolved status.
lock_guard andunique_lockSection: 32.6.5.2[thread.lock.guard], 32.6.5.4[thread.lock.unique]Status:ResolvedSubmitter: Daniel KrüglerOpened: 2010-12-08Last modified: 2016-01-28
Priority:Not Prioritized
View all otherissues in [thread.lock.guard].
View all issues withResolved status.
Discussion:
There are two different*Lockable requirements imposed on template argumentsof the class templatelock_guard as of 32.6.5.2[thread.lock.guard] p. 1+2:
1 [..] The supplied
Mutextype shall meet theBasicLockablerequirements (30.2.5.2).
2 The supplied
Mutextype shall meet theLockablerequirements (30.2.5.3).
TheLockable requirements include the availability of a member functiontry_lock(),but there is no operational semantics in the specification oflock_guard that would relyon such a function. It seems to me that paragraph 2 should be removed.
Mutex shouldalways provide thetry_lock() member function, because several member functions ofunique_lock (unique_lock(mutex_type& m, try_to_lock_t) orbool try_lock()) take advantage of such a function without adding extra requirements for this.It seems that the requirement subsetBasicLockable should be removed.I searched for further possible misusages of the*Lockable requirements, but could notfind any more.[2011-02-23]
Howard suggests an alternative approach in regard tounique_lock: The currentminimum requirements on its template argument should better be reduced toBasicLockable instead of the currentLockable, including ammending member-wise constraints where required. This suggestions was supported by Anthony, Daniel, and Pablo.
[2011-02-24 Reflector discussion]
Moved to Tentatively Ready after 5 votes.
The suggested wording changes are against the working draft N3242.
Remove 32.6.5.2[thread.lock.guard] p. 2 completely:
2 The suppliedMutextype shall meet theLockablerequirements (30.2.5.3).Change 32.6.5.4[thread.lock.unique] p. 1-3 as indicated. The intend is to make
BasicLockablethe fundamental requirement forunique_lock. We also update the note to reflect these changes andsynchronize one remaining reference of 'mutex' by the proper term 'lockable object' in syncto the wording changes oflock_guard:1 [..] The behavior of a program is undefined if the contained pointer
pmis not nulland themutexlockable object pointed to bypmdoes not exist for the entire remaining lifetime (3.8) of theunique_lockobject. The suppliedMutextype shall meet theBasicLockablerequirements (30.2.5.2).[Editor's note:BasicLockable is redundant, since the following additional paragraph requires Lockable.]
2 The suppliedMutextype shall meet theLockablerequirements (30.2.5.3).3 [Note:
unique_lock<Mutex>meets theBasicLockablerequirements. IfMutexmeets theLockablerequirements ([thread.req.lockable.req]),unique_lock<Mutex>also meets theLockablerequirements and ifMutexmeets theTimedLockablerequirements (30.2.5.4),unique_lock<Mutex>also meets theTimedLockablerequirements. —end note ]Modify 32.6.5.4.2[thread.lock.unique.cons] to add the now necessary member-wiseadditional constraints for
Lockable:unique_lock(mutex_type& m, try_to_lock_t) noexcept;8Requires:The supplied
9Effects: Constructs an object of typeMutextype shall meet theLockablerequirements ([thread.req.lockable.req]). Ifmutex_typeis not a recursive mutex the calling thread does not own the mutex.unique_lockand callsm.try_lock().Modify 32.6.5.4.3[thread.lock.unique.locking] to add the now necessary member-wiseadditional constraints for
Lockable:bool try_lock();?Requires: The supplied
4Effects:Mutextype shall meet theLockablerequirements ([thread.req.lockable.req]).pm->try_lock()
Proposed resolution:
Resolved 2011-03 Madrid meeting by paperN3278