04-30-2015 04:51 AM
Hello guys, can anyone provide me a solution aside from producer/consumer loop?
I have two parallel while loops running, however the first loop has some deep code calculation(contains loops and case structure in it) before it process the data that will be on the next loop, is there a way to get the updated data without using the producer/consumer loop?
By the way, both loop is being triggered by a single button and both loops run and read for 100ms interval for other process if there is no press of a button.
Here is the flow of my program:
Press the button
on the first loop, get and compute the value
on the second loop, fetch that value and use it.
Reason for having two loops is for modularity purpose.
Thank you.
04-30-2015 05:47 AM
Hi Nino,
why do you have two parallel loops, when the 2nd one is waiting for a value delivered by the 1st one?
You can use queues (as before with producer-consumer) or local variables, notifiers, AEs aka FGVs, global variables, shared variables, property nodes, DVRs, … to transfer data between loops. Each item has it's advantages and disadvantages!
04-30-2015 06:49 AM
@Nino58 wrote:
Hello guys, can anyone provide me a solution aside from producer/consumer loop?
What's wrong with using Producer/Consumer? It seems to meet your needs. Though, in this case, I'm thinking the Notifier is what you really need.
04-30-2015 06:51 AM
From your problem descriprion, you are producing values in one loop and using them in the other - this is by definition a 'Producer-Conbsumer' architecture, so what makes the producer-consumer design pattern unsuitable? If you described the problem you have with the producer-consumer pattern then we could understand your requirement better.
Are you passing a stream of values from one to the other, or do you just calculate one value in the first loop and, when that has finished, pass it to the second? What data types are your values? Do you have a problem using a queue for some reason? I did not really understand your explanation "the first loop has some deep code calculation(contains loops and case structure in it) before it process the data that will be on the next loop" or why that would be a probelm.