问题
I have a producer Thread as well as consumer thread where producer runs faster than consumer i need to transfer data from producer and process it on consumer, producer will give an array of 1000 elements every second and consumer should wait till it has 10 sets of arrays and will process it (consumer runs every 10 seconds)
i could see that we can modify POSIX message queue to input an array of 1000 elements double array
which is a better method to transfer real data, POXIS message queue or PIPES/Named PIPES?
can this be implemented with PIPES as well?
回答1:
I have a producer Thread as well as consumer thread
When you have a single process, neither POSIX message queues, not pipes are an appropriate solution (both are intended for inter-process communication).
While either can be used, neither should be used, because this solution will be 100 to 1000 times less performant than an appropriate solution, which is to use an appropriate data structure (e.g. std::deque or its C
equivalent).
来源:https://stackoverflow.com/questions/63097731/which-is-better-posix-message-queue-or-pipes-for-producer-consumer-problem