We know that in master/slave and producer/consumer templates we can send information from the master or producer loop, to the slave or consumer loop. But what about getting information from the slave/consumer loop back to the master/producer loop? I'm thinking it might send back some sort of output, or a message saying something like "I completed my work successfully". This can be done with local variables, but is that really a good idea? Is there some other better way? Also, in this case should I just be using a sub-vi? Alhough with a sub-vi I'm not sure I'm still getting the paralell processing offerred by master/slave and producer/consumer.
Solved! Go to Solution.
You can use a notifier to send a message back. You could use a local variable, but unless you know what you are doing, you could run into problems with race conditions.
SubVI's have nothing to do with producer/consumer architectures. You can do a P/C with or without subVI's. SubVI's are a way of breaking down code into meaningful functional blocks.
You should go on the Producer/Consumer road. I always use Dynamic User Events to communicate from the consumer to the producer loop. But User Events are just capable to do much more. You can set up very nice intercommunication between modules for example. Either existing in the same VI (never use more than one Event Structure in a VI, but another can exist of course inside a subVI), or communication method for commands and data between dynamically called VI modules.
A very basic example modifying the Prod/cons (Event) pattern (and not to be used as it is, since no proper error handling, data type should be Typedef enum plus Variant in a typedef cluster, no proper stopping mechnism, etc.):
You can read some more about other usage cases for example here:
I'm curious. What's the value in this? If we are waiting until the consumer loop acts before we do something in the producer loop, why even split the two? You've broken away from parallel processing and now have a very fancy serial process.
Prod reads data and sends to consumer and then waits. Consumer waits until it receves data and then replies allowing producer to continue. Repeat. How is that different from just keeping it in the loop?
Even with notifiers, we will wait and potentially miss notifications depending on loop rates.
One difference is that the two loops can run at different speeds, even if one is waiting on the other. I'm not sure why you would want the producer waiting on the consumer in this case. If the producer is going faster than the consumer you just queue up data and process in the consumer until you have gone through it all.
cuz when the consumer loop is processing data, the main loop still needs to open a relay, and do it at a specified time, a time which may occur before data processing is finished.
this is a unique case
need producer loop to open a relay as discussed above
in my case, if the data processing loops locks up or fails to complete on time, i actually want the vi to stop an notify the user
if it doesn't complete on time, it means there is a problem, and i don't want to the vi to proceed with a problem that may taint the data or result in there not being any data at all
like i said, this is a unique case, in most cases a queue and no loop feedback would be the way to go