which is better POSIX Message Queue or PIPES for producer consumer problem

被刻印的时光 ゝ 提交于 2020-08-20 11:09:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!