Windows 的 Boost Mutex 实现

2021-12-24 00:00:00 windows multithreading c++ boost

据我所知,在旧版本的 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

相关文章