10

Is there any way such that a writer process after sending a mesage to message queue using mq_send(), multiple reader processes can read the message using mq_receive(). I expect 1 write to mq and 1 read from mq, the message is lost.

So I just want to know if my understanding is wrong. Is there any way so that a single writer and multiple reader processes can communicate using posix message queues.

tijko
  • 7,599
  • 11
  • 44
  • 64
jagadeesh
  • 101
  • 1
  • 3

1 Answers1

11

Yes your understanding is correct. You can't do this reliably with POSIX message queues. If you want to communicate the same message to different threads/processes reliably you should use a different queue for each reader.

You can do this if you switch to SYSV message queues. Msgsnd() and msgrcv() can manipulate the message type field of a message in some agreed upon protocol. For instance the writer process will make the message type of the message the PID of the reader process; and the reader process will request to read only messages of that message type. Note that this still requires the writer to write a message for each reader process.

Duck
  • 26,924
  • 5
  • 64
  • 92