c++ - 为什么在c++14中定义了shared_timed_mutex,而在c++17中定义了shared_mutex?

标签 c++ c++14 std c++17

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/

相关文章:

c++ - 如何在编译时推断嵌套std::vector的内部类型?

c++ - 尽可能按引用传递,否则按值传递

c++ - c++ 中的 std::string 与字符串

c++ - std::strtod() 中的十进制错误与 Visual Studio 2015,64 位

c++ - 使用大型系统的编程模板

c++ - Boost::Thread 库不应该与我使用/MD 生成的项目一起部署吗?

c++ - 代码阻止调试器无法启动

c++ - std::bind 分配给 std::function

c++ - 使用 C++ 类方法作为函数回调

c++ - Arduino:字符串连接困难