C++11 引入了 std::mutex
及其扩展版本 - std::timed_mutex
。
但是,在 c++14 中,我们有 std::shared_timed_mutex
,但它的“父级”std::shared_mutex
将在 c+ 中添加+17。
对此有什么合理的解释吗?
如果我不打算使用 std::shared_timed_mutex
的“定时”功能,它会比建议的 std::shared_mutex 更糟(更慢,消耗更多资源)吗?
?
最佳答案
Shared mutex 原来是有计时的,叫做shared_mutex
。
实现者 (msvc iirc) 指出,他们可以在没有时间的情况下“更便宜”地实现它。特别是,SRWLOCK
是 Windows 上现有的原语,足以实现共享互斥锁,但定时需要额外的机器。 (通过@t.c.)。 (但是,我相信它不仅更容易因为已经编写好了,而且从根本上来说更昂贵,至少在 x86/64 窗口上是这样)
向标准添加新类型为时已晚,但重命名它还为时不晚。
所以它被重命名为shared_timed_mutex
,并且在下一个标准中添加了不定时版本。
Here至少是涉及更名的论文之一。
We propose to rename shared_mutex to shared_timed_mutex:
(a) for consistency with the other mutexes (fixing naming inconsistency);
(b) to leave room for a shared_mutex which can be more efficient on some platforms than shared_timed_mutex.
关于c++ - 为什么在c++14中定义了shared_timed_mutex,而在c++17中定义了shared_mutex?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40207171/