本文介绍了我可以使用升压消息队列的线程通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我从一个主线程产卵多个工作线程。我可以从主线程每个线程创建message_queue并从主线程发送消息。我要求这一点,因为消息队列都是为了进程间通信。

I am spawning multiple worker threads from a main thread. Can I create message_queue for each thread from the main thread and send messages from the main thread. Am I asking this because message queues are meant for interprocess communication.

我是否需要考虑这方面的任何具体

Do I need to consider anything specific regarding this

推荐答案

正如Boost消息队列不是基于POSIX消息队列?(和文档中提到的)。如果你在谈论线程你有相同的地址空间,也不需要跨进程的能力。

As mentioned by Boost Message Queue not based on POSIX message queue? (and mentioned in the documentation). If you are talking about threads you have the same address space and do not need inter-process capabilities.

我会建议我的包装类(有-关系)中使用你选择的STL容器和环绕与同步元素的setter /吸气剂(可变排除/互斥体),由How做我创建管理的共享内存段的同步机制的对象的序列化缺失的是一个性能优势的进程间通信 - 流程边界之间复制数据块。在另一方面,你可以使用所有的整洁的功能,例如的shared_ptr

I would advice to use a STL container of your choice within my wrapper class (has-a relationship) and surround the setter/getter with synchronization elements (mutable exclusion/mutex), as mentioned by How do I create synchronization mechanisms in managed shared memory segments? The missing serialization of objects is a performance advantage over inter-process communication -- copy data chunks between processes boundaries. On the other hand you can use all the neat features, e.g. shared_ptr.

这篇关于我可以使用升压消息队列的线程通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 10:36