c++ - 何时使用 pthread_mutex_t

标签 c++ pthreads mutex

有人可以解释一下在什么情况下使用 std::mutex 与 pthread_mutex_t 比较有益。我不明白为什么我们会使用 pthread_mutex_t。谢谢

最佳答案

pthread_mutex_t 是一种 POSIX 解决方案(可用于 linux 和其他 UNIX 系统),在 c++11 将同步原语引入 c++ 库之前就已经存在。您现在应该使用 std::mutex,除此之外,它更跨平台(也可以在 Windows 下使用)。

关于c++ - 何时使用 pthread_mutex_t,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37110571/

相关文章:

c++ - 类和互斥量

C++ 子程序 vector<vector<short>> 指针

c++ - 带线程的 fork 和 core dump

c - 多线程正在以选项卡形式写入输出

pthreads - 线程间数据传输 - Linux

c++ - ACE 互斥体如何工作以及为什么 ACE 线程互斥体的工作方式不同?

C# mutex - 从 ASP.NET 和控制台应用程序调用时出错

c++ - 泛化 C++11 线程类以使用 lambda

c++ - 在 C++/boost 中的 *nix 中检索时间的最有效方法是什么?

2个数字之间的C++随机数重置