对于lock_guard来说,BasicLockable概念似乎已经足够了,但是在标准草案(N3242)中,Mutex模板参数需要Lockable。有什么理由吗?
最佳答案
在 n3290 (§30.4.2.1[thread.lock.guard]/1) 中,它说,
An object of type
lock_guard
controls the ownership of a lockable object within a scope. Alock_guard
object maintains ownership of a lockable object throughout thelock_guard
object’s lifetime (3.8). The behavior of a program is undefined if the lockable object referenced bypm
does not exist for the entire lifetime of thelock_guard
object. The suppliedMutex
type shall meet theBasicLockable
requirements (30.2.5.2).
n3242 中的第二段可能是编辑错误。这是library defect 2023: Incorrect requirements for lock_guard
and unique_lock
,并在n3290中删除该段落,如n3278: Recent Concurrency Issue Resolutions所示
关于c++ - 为什么lock_guard需要Lockable概念,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13901136/