我可以使用升压消息队列的线程通信 [英] Can I Use Boost Message Queues for Thread Communication

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

问题描述

我从一个主线程产卵多个工作线程。我可以从主线程每个线程创建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

推荐答案

正如<一提到href=\"http://stackoverflow.com/questions/408059/boost-message-queue-not-based-on-posix-message-queue-impossible-to-select2\">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 /吸气剂(可变排除/互斥体),由<一提到href=\"http://stackoverflow.com/questions/1321530/how-do-i-create-synchronization-mechanisms-in-managed-shared-memory-segments\">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.

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

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