比 pthread 更快的锁定
我们正在构建一个对延迟极其敏感的应用程序。 我们的完整应用程序除了锁定之外,在一个进程中大约需要 2500 个时钟周期,并且需要获取和释放两个锁。 我们预计 99.98% 的情况下不会发生争用。 使用 pthread 锁定和解锁需要大约 1800 个额外周期。 有更快配方的建议吗? 基于原子操作编写锁可能很棘手。 如果可能的话,我们更愿意使用 Linux 标头或 boost 标头中的标准代码。
We are building an extremely latency sensitive application.
Our full application takes about 2500 clock cycles in a process apart from locking, and there are two locks that need to be acquired and released.
We expect no contention 99.98% of the time.
Using pthread lock and unlock takes about 1800 additional cycles.
Any pointers in faster formulations ?
Writing locks based on atomic operations might be tricky.
We would prefer using standard code as in Linux headers or boost headers if possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
建议尝试使用 英特尔线程构建模块库 中的
spin_mutex
。它是开源的 (GPLv2),因此您还可以检查源代码以获取实现细节。您也可以看看这个: 我的自旋锁实现是否正确且最优?
As a suggestion, try
spin_mutex
from Intel's Threading Building Blocks library. It's open-source (GPLv2), so you can also inspect sources for implementation details.Also you may look at this: Is my spin lock implementation correct and optimal?
你没有太多选择。 Pthread 库尽可能通用。如果你把它做得更具体,那么使用它的人就会更少,因此每个人最终都会实现自己的,弄得一团糟。
恐怕您必须自己编写,特别适合您的要求。我建议阅读:
http://kernel.org/pub/linux/kernel/people /paulmck/perfbook/perfbook.html
我自己在读。
You don't have too many options. Pthread library is as general as possible. If you make it more specific, fewer people will use it, thus everybody ends up implementing their own, making a mess.
I'm afraid you will have to write your own, which specifically suit your requirements. I would suggest this as reading:
http://kernel.org/pub/linux/kernel/people/paulmck/perfbook/perfbook.html
I'm reading it myself.