gpt4 book ai didi

c++ - Mutex 概念与 C++ 中的 Lockable 有何不同?

转载 作者:行者123 更新时间:2023-11-28 06:59:28 25 4
gpt4 key购买 nike

这两个概念似乎需要同一组方法(即 lock、unlock 和 try_lock)。 Mutex 是否要求这些方法支持比 Lockable 更强的语义?

最佳答案

根据 §30.4.1.2/2:

The mutex types shall meet the Lockable requirements (30.2.5.3).

但是,

§30.4.1.2/3 添加:

The mutex types shall be DefaultConstructible and Destructible. If initialization of an object of a mutex type fails, an exception of type system_error shall be thrown. The mutex types shall not be copyable or movable.

§30.4.1.2/3 添加了另一项要求,指定互斥类型要使用的精确错误代码。

底线:互斥锁是可锁定的,但也增加了一些更具体的限制。

关于c++ - Mutex 概念与 C++ 中的 Lockable 有何不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22703439/

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