开发者

Can I Use Boost Message Queues for Thread Communication

开发者 https://www.devze.com 2023-01-12 09:19 出处:网络
I am spawning multiple worker thr开发者_开发问答eads 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 becaus

I am spawning multiple worker thr开发者_开发问答eads 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消