Should read mq_receive
and write mq_send
be protected by semaphores when accessing a queue in a multiprocess program or is there any sort of protection alredy built in
Asked
Active
Viewed 170 times
0

federicoporritos84
- 11
- 5
-
Shared resources between threads need synchronisation for data integrity & consistency. – जलजनक Mar 31 '22 at 21:10
-
@SparKot The idea of message queues, that they implement the inter-process synchronization intrinsically. – Eugene Sh. Mar 31 '22 at 21:13
-
*is there any sort of protection already built in* - yes, there is. This is exactly the idea of having message queues. – Eugene Sh. Mar 31 '22 at 21:34
1 Answers
1
It's always recomended to read the formal documentation for API you are using.
Specifcally for mq_receive
and mq_send
these are:
- https://man7.org/linux/man-pages/man3/mq_send.3.html
- https://man7.org/linux/man-pages/man3/mq_receive.3.html
In the atributes section you can see that both these functions are thread safe, meaning you can access them from multiple threads without additional protection.

wohlstad
- 12,661
- 10
- 26
- 39