Can I Use Boost Message Queues for Thread Communication

情到浓时终转凉″ 提交于 2019-12-21 17:38:57

问题


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


回答1:


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.

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.



来源:https://stackoverflow.com/questions/3541535/can-i-use-boost-message-queues-for-thread-communication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!