12-21-2019 06:29 PM
Hello everyone!
I have been recently learnning about communications among threads and The Actor Framework. An easy question come up: think of a simple model-----a producer loop and a consumer loop. Datas are transmitted from producer to consumer and there are three data-types:
1. enumeration, which lists all possible messages told by the producer to that consumer.
2. such like a long waveform or a large matrix usually, big data needed by the consumer.
3. an indicator telling consumer that whether the transmitting message is valid or not.
And the case is: a big subset of all possible messages are not needed to carry data, only a small subset of messages are transmitted with data and the 3rd type "indicator" is optional.
So one may use two or three queues(enum-queue, data-queue, optional indicator-queue) or may use one queue(cluster-queue, the three data-types are bundling).
I wonder how to choose the style, which is better? especially when it comes to performance or maintance?
Thanks!
12-21-2019 08:52 PM
Wow. I have no idea what you are talking about! Maybe a code example so we understand the three Data Types?
Bob Schor
12-22-2019 07:51 AM
One queue. Absolutely and definitely. Else how could you possibly know how to correlate "message", "data", and "validity"? Which data goes with which message? Which validity flag corresponds to which data?
But keep them together in a cluster (a *typedef'ed* cluster, BTW), there can be no doubt how to correlate them.
-Kevin P
12-22-2019 08:24 PM - edited 12-22-2019 08:25 PM
@Bob_Schor 已写:
Wow. I have no idea what you are talking about! Maybe a code example so we understand the three Data Types?
Bob Schor
Sorry I didn't make myself clearly and I agree that an example code will bring convenience.
The answer I wonder is which style is better.
12-22-2019 08:49 PM
Bundle the data types. 1 Queue.
The problem with 3 different queues is that the loop won't iterate until there is in element in each of the queues. If one queue gets more elements than the others, then that queue will fill up with data since it can't dequeue something until all queues get an item and the loop rolls around again.
Also, as others have said, individual queues means there isn't any real relationship between the queues, while when you bundle the data, you know the 3 data elements belong together when you dequeue them, because you put them in the queue together!