升压C ++锁定无队列VS共享队列 [英] boost c++ lock-free queue vs shared queue

查看:222
本文介绍了升压C ++锁定无队列VS共享队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在多线程编程很新,我只知道最常见的生产者 - 消费者队列。
我使用Boost C ++库,我不知道,如果是更好地利用升压:: lockfree ::队列或周围的std ::队列中的包装类,使用`mutex`和`condition_variable`。

I'm quite new in multithreading programming, I just know the most common Producer-Consumer-Queue. I'm using the boost c++ libraries and I don't know if is better use boost::lockfree::queue or a wrapper class around std::queue that is using `mutex` and `condition_variable`.


凡利用好免费的锁定数据结构和哪里是好是使用基于`mutex`和`condition_variables`一个简单的实现?

Where is better using lock free data structures and where is better is use a simple implementation based on `mutex` and `condition_variables`?

推荐答案

尝试无论是在你的应用程序,看看哪个效果最好。

Try both in your app, see which performs best.

通常情况下,轮询无锁队列效果最好,当队列几乎总是有条目,一个阻塞​​队列时效果最好的队列几乎总是空的。

Typically, polling a lock-free queue works best when the queue nearly always has entries, a blocking queue works best when the queue is nearly always empty.

阻塞队列的缺点是潜伏期,一般为2-20美国的订单,由于内核的信号。这可以通过使由消费者线程在每个排队产品的工作时间比此时间长很多设计系统来减轻。

The downside of blocking queues is latency, typically of the order of 2-20 uS, due to kernel signaling. This can be mitigated by designing the system so that the work done by the consumer threads on each queued item takes much longer than this interval.

非阻塞的队列的缺点是CPU和内存带宽,同时轮询空队列的浪费。这可以通过使得队列很少空系统设计来减轻。

The downside of non-blocking queues is the waste of CPU and memory bandwidth while polling an empty queue. This can be mitigated by designing the system so that the queue is rarely empty.

截至被评论者已经暗示,非阻塞队列在单CPU系统中一个非常糟糕的主意。

As already hinted at by commenters, a non-blocking queue is a very bad idea on single-CPU systems.

这篇关于升压C ++锁定无队列VS共享队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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