gpt4 book ai didi

c++ - 为什么 lock_guard 需要 Lockable 概念

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:52:46 24 4
gpt4 key购买 nike

对于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. A lock_guard object maintains ownership of a lockable object throughout the lock_guard object’s lifetime (3.8). The behavior of a program is undefined if the lockable object referenced by pm does not exist for the entire lifetime of the lock_guard object. The supplied Mutex type shall meet the BasicLockable requirements (30.2.5.2).

n3242 中的第 2 段可能是编辑错误。这是 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com