lock_guard and unique_lockSection: 32.6.5.2 [thread.lock.guard], 32.6.5.4 [thread.lock.unique] Status: Resolved Submitter: Daniel Krügler Opened: 2010-12-08 Last modified: 2016-01-28
Priority: Not Prioritized
View all other issues in [thread.lock.guard].
View all issues with Resolved status.
Discussion:
There are two different *Lockable requirements imposed on template arguments
of the class template lock_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).
The Lockable requirements include the availability of a member function try_lock(),
but there is no operational semantics in the specification of lock_guard that would rely
on such a function. It seems to me that paragraph 2 should be removed.
Mutex should
always provide the try_lock() member function, because several member functions of
unique_lock (unique_lock(mutex_type& m, try_to_lock_t) or bool try_lock())
take advantage of such a function without adding extra requirements for this.
It seems that the requirement subset BasicLockable should be removed.
I searched for further possible misusages of the *Lockable requirements, but could not
find any more.
[2011-02-23]
Howard suggests an alternative approach in regard to unique_lock: The current
minimum requirements on its template argument should better be reduced to BasicLockable
instead of the current Lockable, 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 and synchronize one remaining reference of 'mutex' by the proper term 'lockable object' in sync to the wording changes oflock_guard:1 [..] The behavior of a program is undefined if the contained pointer
pmis not null and 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-wise additional constraints for
Lockable:unique_lock(mutex_type& m, try_to_lock_t) noexcept;8 Requires: The supplied
9 Effects: 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-wise additional constraints for
Lockable:bool try_lock();? Requires: The supplied
4 Effects:Mutextype shall meet theLockablerequirements ([thread.req.lockable.req]).pm->try_lock()
Proposed resolution:
Resolved 2011-03 Madrid meeting by paper N3278