快速 C++ 单生产者单消费者实现 [英] Fast C++ single producer single consumer implementation

查看:71
本文介绍了快速 C++ 单生产者单消费者实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种单生产者、单消费者 FIFO 实现,它的执行速度比普通的 lock-write-unlock-signal/waitForSignal-lock-read-unlock 的东西快.我正在寻找用 C 或 C++ 编写的大多数 POSIX 操作系统(x86 特定的很好)支持的东西.

I'm looking for a single-producer, single-consumer FIFO implementation that would perform faster than the normal lock-write-unlock-signal / waitForSignal-lock-read-unlock stuff. I'm looking for something supported by most POSIX operating systems (x86 specific is fine) written in either C or C++.

我不想传递比指针大的东西.

I'm not looking to pass anything larger than a pointer.

我不一定喜欢无锁的想法,但我确实想要一些快速而正确的东西.我读到的一篇关于这个主题的论文提到了一种看起来很有趣的双队列方法,但从那时起我就找不到太多关于它的信息.

I'm not necessarily attached to the lock-free idea, but I do want something fast and correct. One of the papers I read on the subject mentioned a two-queue approach that seemed interesting, but I haven't been able to find much about that since then.

从我迄今为止所做的研究来看,0mq(据说它的 inproc://方案使用无锁结构)看起来是最有吸引力的选择.话虽如此,我想确保在走上这条路之前我没有错过任何东西.

From the research I've done so far, 0mq (which supposedly uses a lock-free structure for its inproc:// scheme) looks like it's the most attractive option. That being said, I'd like to be sure I haven't missed anything before I go down that path.

另一种选择可能涉及使用 POSIX 消息队列,但这对于线程 <--> 线程通信来说似乎相当慢;这是真的吗?

One other alternative might involve using a POSIX message queue, but this seems like it'd be rather slow for thread <--> thread communication; is this true?

任何单消费者单生产者C 中的无锁队列实现? 似乎相关,但公认的答案确实没有像过早优化不好"那样枚举现有库.

Any single-consumer single-producer lock free queue implementation in C? seems relevant, but the accepted answer there really isn't an enumeration of existing libraries as much as it is "premature optimization is bad".

推荐答案

您将需要查看英特尔的线程构建块.它们建立在 x86 的用户模式原子操作和 pthread 或 Win32 线程提供的原语之上,并提供快速、高效、模板化的数据结构.并发队列是其中之一.

You will want to look at Intel's Thread Building Blocks. They build on the primitives provided by x86's user-mode atomic operations, and pthreads or Win32 threads, and provide fast, efficient, templated data structures. A concurrent queue is among many.

这篇关于快速 C++ 单生产者单消费者实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆