Windows 的 Boost Mutex 实现

2023-07-19C/C++开发问题
2

本文介绍了Windows 的 Boost Mutex 实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

据我所知,在旧版本的 Boost boost::mutex 中,Windows 的实现是使用临界区完成的.但是在 Boost 1.51 的最新版本中,我发现现在互斥锁的实现是基于事件的.

As far as I know in old versions of Boost boost::mutex implementation for Windows was done using critical sections. But in the newest version of Boost 1.51 I discovered that now mutex implementation is based on Events.

有人知道这种变化背后的原因是什么吗?是因为性能原因吗?临界区会被弃用吗?

Does anybody know what is the rational behind this change? Was it done because of performance reasons? Do critical sections become deprecated?

推荐答案

通过使用 boost,我们总是有最好的方法而不做任何改变,这不是很好吗?在新版本的 boost 中,boost::mutex 被实现为一个自旋锁,但在 Windows 事件的帮助下避免忙等待,并且该事件只会在需要时创建,因此它非常轻量级并且具有非常高的性能并且还使 boost 能够使用这个轻量级的 mutex 进行定时等待!我觉得这个很棒

Isn't it wonderful that by using boost we always have best approach with no change? In new version of boost, boost::mutex is implemented as an spinlock but with the help of a windows event to avoid busy wait and that event will only created if needed, thus it is very light weight and have a very high performance and also enable boost to use this light weight mutex for timed wait! I think this is excellent

这篇关于Windows 的 Boost Mutex 实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

无法访问 C++ std::set 中对象的非常量成员函数
Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)...
2024-08-14 C/C++开发问题
17

从 lambda 构造 std::function 参数
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)...
2024-08-14 C/C++开发问题
25

STL BigInt 类实现
STL BigInt class implementation(STL BigInt 类实现)...
2024-08-14 C/C++开发问题
3

使用 std::atomic 和 std::condition_variable 同步不可靠
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)...
2024-08-14 C/C++开发问题
17

在 STL 中将列表元素移动到末尾
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)...
2024-08-14 C/C++开发问题
9

为什么禁止对存储在 STL 容器中的类重载 operator&()?
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)...
2024-08-14 C/C++开发问题
6