boost :: asio :: strand&& boost :: lockfree :: spsc_queue [英] boost::asio::strand && boost::lockfree::spsc_queue

查看:85
本文介绍了boost :: asio :: strand&& boost :: lockfree :: spsc_queue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我正在使用线程池运行单个boost::asio::io_service并使用boost::asio::strand来包装特定的套接字接收来模拟单线程操作,那么有人知道该线程是否满足安全地产生到即使我将使用不同的线程进行生产,但保证一次只能生产一个.

If I am running a single an boost::asio::io_service with a thread pool and wrapping a particular socket receive using a boost::asio::strand to simulate single threaded operation, does anyone know if the strand meets the requirements to safely produce to a boost::lockfree::spsc_queue even though I will be producing from different threads but guaranteed to only produce one at a time.

推荐答案

是.通过链进行序列化可以保证您所需要的.稍微扩展一下,如果您有多个支架(例如,用于多个插槽),则跨推到同一队列的多条线不存在这种保证.

Yes. Serialization through a strand guarantees what you are after. To extend this a little bit, if you have multiple stands (for multiple sockets for example) - then no such guarantee exists across multiple strands pushing to the same queue.

这篇关于boost :: asio :: strand&& boost :: lockfree :: spsc_queue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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