I have a 'producer' object, that steps through some data and emits various signals depending on what data item is next in the queue.
Each of those signals are processed by at most one 'consumer' object at a time (it takes care to disconnect its slots before attaching the producer's signals to the other consumer).
If the processing on the consumer side fails for whatever reason, the processing of the queue must stop, as there is no point in going ahead with it.
What would be the optimal way of letting the producer know, that no further processing is needed because of an exceptional condition? Since the consumers have a pointer to the producer, I would imagine, that there could be multiple ways, its just that I am not sure if they are race-condition-safe (I don't know if I can depend on the order in which signals are emitted / processed).
Two ways I can think of:
- set a flag on the producer, that can be checked on the next iteration so that it will know that it is time to stop
- register a signal on the consumer (and a corresponding slot on the producer), that will be emitted when processing should be halted
I am wondering if these solutions are viable at all in the following scenarios:
- producer and consumer(s) belong to the same thread
- producer and consumer(s) belong to different threads
In short, I have to make absolutely sure, that no additional processing will happen if the consumer reports an error.
As you can probably guess, I am not very familiar with Qt's idioms for such things yet.