Take the 2-minute tour ×

I'm working on a wide program (C++/Qt on linux) organized in different parts: from an inner engine toward different UI (some of them graphical). So far I've organized this division creating a number of different processes equal to the number of different UI and engine. Every "user" process communicates with the core engine via two pipes (opposite directions).

What I would like to obtain is to have every single process running as a stand alone one that doesn't block while communicating with the engine process but simply using an internal custom "message buffer" (already built and tested) to store messages and process them when free.

The solution is (I guess) to design every process to spawn an additional thread which takes care of communicating to engine process (and another one for GUI). I am using pthread.h library (POSIX). Is it right? Could someone provide a simple example of how to achieve a communication between a single couple of processes?

Thanks in advance.

share|improve this question
What about a simple textual protocol, a socket (or pipes) and select instead of threads ? –  Alexandre C. Nov 7 '12 at 16:53
@AlexandreC. Do you mean the process periodically (or whenever is free) checking for new message on a pipe? –  schu Nov 7 '12 at 17:06
yes, in a non blocking manner (with select). This can go to another thread if you want to (and it introduces potential problems, as you surely know). I'd go multithreaded here only if the main loop does lengthy uninterruptible tasks. –  Alexandre C. Nov 7 '12 at 17:45
I agree with Alexandre. Maybe you can use boost asio to make asynchronous io communication - it is very good for that... –  Filipe Nov 7 '12 at 18:17
thanks both. since my UI try to achieve the MVC model, i think i will end up with a parallel thread inside the controlled dedicated to checking for new incoming messages by using "select" (or waiting on the pipe) –  schu Nov 8 '12 at 10:32

Your Answer



Browse other questions tagged or ask your own question.