如何快速是无可争议的锁? [英] How fast is an uncontested lock?
问题描述
和多少快/慢它比一个无可争议的原子变量(如原子c为C的> ++)操作。此外,慢多少是有争议的原子变量相对于无争议的锁?我工作的体系结构的x86-64。
And how much faster/slower it is as compared to an uncontested atomic variable (such as atomic<> of C++) operation. Also, how much slower are contested atomic variables relative to the uncontested lock? The architecture I'm working on is x86-64.
推荐答案
有GitHub上一个项目,此测量的目的的在不同的平台。不幸的是,我的硕士论文后,我从来没有真正跟进这一点,但至少基本的code是那里的时候。
There’s a project on GitHub with the purpose of measuring this on different platforms. Unfortunately, after my master thesis I never really had the time to follow up on this but at least the rudimentary code is there.
它衡量的pthreads和OpenMP锁,相比于 __ sync_fetch_and_add
内在的。
It measures pthreads and OpenMP locks, compared to the __sync_fetch_and_add
intrinsic.
从我记得,我们期待锁和原子操作之间的pretty大的差别(〜一个数量级),但真正的区别竟然是非常小的。
From what I remember, we were expecting a pretty big difference between locks and atomic operations (~ an order of magnitude) but the real difference turned out to be very small.
不过,在我的系统产生的结果反映我原来的猜测,现在测即(无论是否pthreads的或使用的OpenMP)原子操作要快五倍,和一个锁定的增值业务需要大约为35ns(包括获取锁,进行增量,并且解除锁定)。
However, measuring now on my system yields results which reflect my original guess, namely that (regardless of whether pthreads or OpenMP is used) atomic operations are about five times faster, and a single locked increment operation takes about 35ns (this includes acquiring the lock, performing the increment, and releasing the lock).
这篇关于如何快速是无可争议的锁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!