Does a POSIX message queue go through kernel space?

I am looking to use POSIX message queues in a single multi-threaded process application. mqueues will be used to exchange data between threads.

I'm a little confused about how they work in the Linux kernel. Are all messages made through kernel space, and then back to user space on reception? aka from user space stream. I do mq_send and the message ends in kernel space, and then upon receiving it is another system call to get the message from kernel space. If it is not so much inefficient for high-level message queues?

+6
linux posix message-queue
source share
2 answers

Yes, they will always go through the kernel (and are usually used for interprocess communication). If you just need cross-threading, you can probably do it. simple work queue (using old old mutexes).

If you want something with a lot of features, you are almost certainly better off looking at something like AMQP.

Traditionally, Unix / Linux uses sockets + read / write instead, but it depends on what you want (and how you want to use it).

+7
source share

Well, I have to object to the fact that MQs are "highly" ineffective.

True, there are some overheads associated with copying data to / from the kernel and for really high-performance applications, this may be a real consideration and the reason for using shared or heap memory.

But the disadvantage of well-written MQ shared memory code is the fastest IPC, which has significant built-in features. The synchronization headaches are removed and (at least on Linux) the message queue descriptor (mqd_t) can be used as a file descriptor in the select () clause. This allows you to achieve significant flexibility to do something other than expecting a mutex or continuous polling. In addition, MQs are permanent kernels, and this is a nice little feature if it is important that the data in the queue wait for the application to crash.

+5
source share

All Articles