I understand that POSIX Message Queues do not require synchronization between different processes. However, how safe are they when being accessed by multiple threads in a single process?
I read this question: Does message queue support Multi-thread? which pertains to SysV Message Queues, and I would assume that POSIX has at least the same support. It seems to imply yes they are thread safe, however:
"Any resource which is shared globally among threads or processes is subject to race conditions"
This would lead me to believe that intra-process synchronization is still required.
In my case in particular both processes that communicate using the message queue implement the 'boss-worker' pattern, and therefore workers can collide into race conditions when attempting to perform operations on the message queues. Would my assumption be correct in stating that access to these queues still requires synchronization within each process?
If you're passing memory addresses of shared memory (either between threads in a process, or memory that's shared between processes) as the contents of your messages, then you still need memory synchronization to access that memory once you read its address out of the message. But you do not need any additional synchronization to perform operations on the message queue itself (aside from destroying it, which you should not do until the last user has finished with it, of course). That's the whole point of having message queues.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With