Showing results for 
Search instead for 
Did you mean: 

Recommended way of wiring queue RefNum?


@Mark_Yedinak wrote:

@Kyle97330 wrote:

I take the general approach that anything that goes in a shift register in a loop is something that could change from iteration to iteration.


Unless you have multiple queues that you're switching between, or creating and destroying them as you go, a queue reference never changes and is therefore something that shouldn't go in a shift register.


One small other thing is that in either of those situations, I would recommend that the consumer loop be the one that triggers the closing of the reference as a general rule.  If the producer loop finishing destroys the reference, then there's a chance that there will be unexecuted consumer loop actions that never happen.  If that's what you want, enqueue a "stop" action to the front of the queue to get the same effect.  Some producer/consumer loops treat the destruction of the queue as a "stop" action but that can lead to skipped queue elements, and it's not hard at all to just add "stop" as one more action.

There is one issue with this approach and that is if your wire a reference through a For loop using just a terminal and need the reference output from that For loop you will run into problems if the loop executes 0 times. If the For loop doesn't execute, such as the iteration value if 0 or the array driving the loop is empty, the reference will be lost. The output from the For loop will be an invalid reference, not what you wired into the loop. 

I am aware of that in general, but as this was a discussion about producer-consumer loops, those should always be "While" loops so it didn't seem worth mentioning.

0 Kudos
Message 11 of 13

Okay, I got that. If I let the consumer loop destroy the queue (upon a 'stop' action), will that stop the producer loop as well? What to wire to the stop terminal of the producer loop? Also, how to deal with the unregister from events - it is very unclear to me when this will be executed in that case...


Thanks for your help!

0 Kudos
Message 12 of 13

Destroying the queue will result in any current or future queue operations on the reference generating an error immediately.  So the first example, where the producer loop has the "Stop" terminal of the while loop wired up to the error chain would stop the next time any case in it ran, but the second example would not.


However, you would usually want the producer loop to enqueue the "stop" command while also stopping itself on the same loop iteration.

0 Kudos
Message 13 of 13