From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Master/Slave Producer/Consumer Feeback?

Solved!
Go to solution

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.

0 Kudos
Message 1 of 7
(3,552 Views)
Solution
Accepted by wnb

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.

Message 2 of 7
(3,544 Views)

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.):

 

ProducerConsumerEvents 1_BD.png

 

You can read some more about other usage cases for example here:

http://forums.ni.com/t5/LabVIEW/Triggering-a-user-event-in-one-subVI-from-another-subVI/m-p/3317337

 

Official docs: http://zone.ni.com/reference/en-XX/help/371361K-01/lvhowto/creating_user_events/

Message 3 of 7
(3,517 Views)

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.

0 Kudos
Message 4 of 7
(3,486 Views)

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.

 

Aaron Douglass
Applications Engineer
National Instruments
0 Kudos
Message 5 of 7
(3,443 Views)

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.

 

0 Kudos
Message 6 of 7
(3,364 Views)

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

0 Kudos
Message 7 of 7
(3,363 Views)