LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Releasing Queue in Producer Consumer model



Notice also that the error in to the Release Queue is not wired.  If there were an error, the Release would not take place.  All errors are merged at the end to report exactly where an error occured.  A timeout is included in case an error prevents the stop command from being enqueued or dequeued.


This is incorrect.  Release Queue (at least in more recent versions of LabVIEW, since queues became primitives) will release the queue even if an error is passed into the error in terminal.  Nearly all functions that destroy a reference operate this way, so that references can be closed cleanly even if an error occurs.

Test it out - make a VI that contains an obtain queue, and a release queue and dequeue element in parallel.  Set the timeout of dequeue element to -1 and wire an error into the release queue.  The VI terminates immediately, indicating that the queue was destroyed and dequeue element stopped waiting.  If the queue still existed, the code would sit there and wait.
Message 11 of 25
(2,485 Views)
I wasn't aware of this.  Thanx for pointing it out.  Most functions don't operate when an error in is present.  I wasn't taking any chances.
- tbob

Inventor of the WORM Global
0 Kudos
Message 12 of 25
(2,480 Views)
Another thought to add to the genesis of the UBER producer consumer template.  What about adding a check on the error cluster after the enqueue and OR'ing that with the stop code.  That way, in case the queue crashes the VI can exit in a controlled manner?

Latest iteration attached with that change and the reconnection of the error out from the consumer loop since the release will release even on error in.

Cheers,
Greg Cole
“It is not the ship so much as the skillful sailing that ensures the prosperous voyage.”
0 Kudos
Message 13 of 25
(2,474 Views)

Greg,

Can you pl repost the VI saved for LV 7.1 ?

- Partha ( CLD until Oct 2027 🙂 )
Message 14 of 25
(2,454 Views)
Sorry Partha,

Looks like I can only save back to version 8.0.  I faintly remember I had disk  space issues and had to make some room a while back.

Can anyone else do a save back and post?

Cheers,
Greg Cole
“It is not the ship so much as the skillful sailing that ensures the prosperous voyage.”
0 Kudos
Message 15 of 25
(2,437 Views)

Can anyone else do a save back and post?

Done.
0 Kudos
Message 16 of 25
(2,433 Views)

Hi,

If an error occurs in the producers loop the vi cannot be stopped. To prevent this one can enqueue a stop in case of error from the producers loop. See the attached LV 8.2.1 file (cannot save for earlier version).

BR

Sture

0 Kudos
Message 17 of 25
(2,427 Views)
I'm not sure if that will fly.  If the queue is busted and the enqueue fails inside the producer loop, what assurance is there that the enqueue you add following the producer loop will execute?

The logic is, if the enqueue fails inside the producer loops it exits on error.  The code then assumes that the first dequeue in the consumer will also fail and provide an error out to end the consumer loop.  Does anyone know if this would ever not be the case?  Further, with the timeout wired would a dequeue return error or no error when trying to dequeue on a busted queue...  holy cow, say that three times fast.  Smiley Very Happy

@Sture wrote:
Hi,
If an error occurs in the producers loop the vi cannot be stopped. To prevent this one can enqueue a stop in case of error from the producers loop. See the attached LV 8.2.1 file (cannot save for earlier version).
BR
Sture

Cheers,
Greg Cole
“It is not the ship so much as the skillful sailing that ensures the prosperous voyage.”
0 Kudos
Message 18 of 25
(2,414 Views)

 I tested by inserting an error in the producer loop. Since the producer loop is stopped on error there is no way to stop the consumer loop anymore. Dequeue element returns error only if it is called after release queue is done. Therefore I think one have to enqueue a stop ( or release queue) if producer loop returns error.

/Sture

0 Kudos
Message 19 of 25
(2,401 Views)
I can see that logic, but the queue has not broken in that example so I would expect the consumer loop to keep running.  I do like the idea tho.
If you get an error into the shift reg in the producer (for whatever reason) having a case hanging outside the loop to release the queue would be good insurance for closing down the consumer loop.

But then the possibility arises of all the pushed events not being processed by the consumer.  However, if you're crashing out on error codes anyway perhaps that point is moot?

Latest iteration attached, 8.2.1 again.

@Sture wrote:

 I tested by inserting an error in the producer loop. Since the producer loop is stopped on error there is no way to stop the consumer loop anymore. Dequeue element returns error only if it is called after release queue is done. Therefore I think one have to enqueue a stop ( or release queue) if producer loop returns error.
/Sture


Cheers,

Greg Cole
“It is not the ship so much as the skillful sailing that ensures the prosperous voyage.”
0 Kudos
Message 20 of 25
(2,394 Views)