boost :: asio :: strand&& boost :: lockfree :: spsc_queue [英] 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屋!