I'm writing a program in which several producers generate some data that should be processed by several consumers. Since the consumption of each piece of data takes around 100ms and the target platform has many processors, it seems natural to me that each producer and each consumer gets its own thread. My question is: Are Qt signals/slots a good way for passing data blocks from producers to consumers? Or do you suggest a better solution (Qt is strongly preferred).
Just in case it's relevant, the producers produce data in bursts of several hundred thousands every hour or so.
I don't think the signal/slot mechanism is appropriate here, because each signal is distributed to all connected slots. This means that if you use the signal/slot mechanism as your 'work queue', you don't get any load distribution over the consumers, but rather that all consumers get to do the same (duplicate) work.
A better mechanism would be to use a container as work queue (producers add items to the container, consumers remove them), with a QMutex
to avoid concurrency problems and one (or two, if you want to impose a maximum size) QWaitCondition
to block the consumers when there is no work for them.