4

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

Sirish
  • 7,948
  • 19
  • 61
  • 97

1 Answers1

4

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.

Community
  • 1
  • 1
Raphael Bossek
  • 1,799
  • 12
  • 22