I’m considering a multi-threaded architecture for a processing pipeline. My main processing module has an input queue, from which it receives data packets. It then performs transformations on these packets (decryption, etc.) and places them into an output queue.
The threading comes in where many input packets can have their contents transformed independently from one another.
However, the punchline is that the output queue must have the same ordering as the input queue (i.e., the first pulled off the input queue must be the first pushed onto the output queue, regardless of whether its transformations finished first.)
Naturally, there will be some kind of synchronisation at the output queue, so my question is: what would be the best way of ensuring that this ordering is maintained?
With the following assumptions
listener
handle and a pointer to worker/output data
worker threads
I would consider the following flow:
Input queue listener does these steps:
Worker thread does the following:
extract a pointer to an output
message from it
consumer does the following:
extract a pointer to an output
message from it