Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Posix message queue - multi writer & multi reader

I am confused about the queue (POSIX). Does multiple writer to queue or multiple reader from a queue needs to be protected?

multiple threads will write to the queue and multiple threads will read from the queue.

As the definition says "A message queue can have many readers and many writers ". But it is not saying if it needs protection or not. should these two messages be protected by mutex?

mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio); mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio);

Please can anyone help me? Thanks in advance.

like image 583
Mariwan Avatar asked Oct 21 '11 20:10

Mariwan


1 Answers

No you don't need to protect them with a mutex or such. The kernel takes care of it.

See the "ATTRIBUTES" section of the mq_send man page online ("Thread Safety" is "MT-Safe").

like image 147
Duck Avatar answered Nov 06 '22 23:11

Duck