简体   繁体   English

提升线程间通信队列

[英]Boost interthread communication queue

I'm using Boost::interprocess::message_queue to enable communication between threads on my application. 我正在使用Boost :: interprocess :: message_queue来启用我的应用程序上的线程之间的通信。 I'm doing so for two reasons. 我这样做有两个原因。 First, because I don't need to directly implement a shared mem. 首先,因为我不需要直接实现共享内存。 synchronization mechanism and second because I want to model the system this way because in the future it may change to interprocess. 同步机制和第二,因为我想以这种方式建模系统,因为将来它可能会改变为进程间。

My question is: Is there any more apropriate mechanism to enable interthread communication given this restrictions or I can continue using interprocess queue without fear for 'interprocess overhead'? 我的问题是:在这种限制下是否有更多适当的机制来启用线程间通信,或者我可以继续使用进程间队列而不用担心“进程间开销”?

You could use a std::queue protected by a boost::mutex & boost::condition_variable 你可以使用受boost::mutexboost::condition_variable保护的std::queue

Anthony Williams provides an excellent explanation on how to implement a thread safe queue in his book 'C++ Concurrency in Action'. Anthony Williams在他的“C ++ Concurrency in Action”一书中提供了关于如何实现线程安全队列的出色解释。

Example code is available on his website here: 示例代码可在他的网站上找到:

Just Software Solutions - Implementing a Thread Safe Queue Just Software Solutions - 实现线程安全队列

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM