[英]Portable Writer-Readers spinlock
I used boost::shared_mutex
as synchronization objects in Writer-Readers model. 我使用
boost::shared_mutex
作为Writer-Readers模型中的同步对象。 However, it's considerably slow compared with no locks used (In my test: without any readers, to write 500,000 values it takes 100 msec if no locks used and ~500 msec if boost::shared_mutex
used). 但是,与不使用锁相比,它的速度相当慢(在我的测试中:没有任何读取器,要写入500,000个值,如果不使用锁,则需要100毫秒;如果使用
boost::shared_mutex
则需要约500毫秒)。 That's why I decided to consider something like spinlock. 这就是为什么我决定考虑使用自旋锁的原因。 I would like to make a portable spinlock (Windows + Linux).
我想制作一个便携式自旋锁(Windows + Linux)。
InterlockedCompareExchange
, YieldProcessor
, InterlockedDecrement
on Linux. InterlockedCompareExchange
, YieldProcessor
和InterlockedDecrement
。 Update 2016/03/08 更新2016/03/08
I found out a guide and the implementation released by facebook on github. 我找到了一个指南,并在github上由facebook发布了实现 。 Haven't tried it yet.
还没有尝试过。 I updated here for anyone who will have the same question and might want to refer.
我在这里为有相同问题并可能希望参考的任何人更新。
There exists no portable solution for C++03 because C++03 has no memory model but you can implement it very easily by just copying atomic_flag
implementations of your target platform. C ++ 03没有可移植的解决方案,因为C ++ 03没有内存模型,但是您可以通过复制目标平台的
atomic_flag
实现非常容易地实现它。
My comment for the given link/tutorial: volatile
should not be used by an application programmer unless you access unusual memory. 我对给定链接/教程的评论:除非您访问异常内存,否则应用程序程序员不应使用
volatile
。 I recommend this and all others articles of that topic. 我推荐该主题的所有文章。 There should be a ready to use library for download.
应该有一个可供使用的库可供下载。 I do not know if it is C++11 only.
我不知道是否只有C ++ 11。
I assume you are not very experienced with multithreading, synchronization and locks. 我假设您对多线程,同步和锁没有很丰富的经验。 Whatever you want to achieve, just go the standard route first and came back later if your performance is not enough.
无论您要实现什么目标,只要您的性能不够,就先走标准路线,然后再返回。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.