Showing results for 
Search instead for 
Did you mean: 

Program hangs when stopping consumer loop

Go to solution

Hello, I made program that uses occurrences, it's similar to example provided with LabVIEW, but I don't know why it's hanging when I trying to stop consumer loop. The True value is passed by Global Variable and than nothing is happening.
What am I doing wrong?
I know that occurrencies and variables are not best for such purpose, but I have to make some program with them because I'm preparing some workshop to my friends about synchronization pallete.

I'm using LabVIEW 2016 32bit.

Thanks for any clues 😉

Download All
0 Kudos
Message 1 of 13

In your consumer loop you are waiting on an occurance, that is never going to happen because you havent wired anything to it.  Remove that occurance and i the application will work.

0 Kudos
Message 2 of 13

This architecture is too weird to be coded correctly.  I don't think this is a good way to teach someone how to use an occurence.


Maybe you could explain what you're trying to show them in more detail and we can come up with something.  🙂

(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 3 of 13

Well I was asked for whole pallete so I'm doing that 😉 What I wanted? simple occurence counter as in example

I did as they wrote in Simple Occurence Example:

"Stopping the Two Loops:

The Loop Stop global variable is initialized before Loop 1 and Loop 2 start. Then, when the user clicks the Stop button, the top loop stops, sets the Loop Stop global variable to TRUE, and sets the occurrence. This causes Loop 2 to wake up, read the TRUE value of the Loop Stop global variable, and stop executing."

0 Kudos
Message 4 of 13

But the application works, and the consumer loop are receiving concurrences from producer loop so it's executing smoothly. Problem occurs when I'm trying to stop that app -  it hangs on consumer loop.

0 Kudos
Message 5 of 13

Remove the occurance in the consumer loop.

0 Kudos
Message 6 of 13

Consumer loop is triggered by Occurrence so I can't remove it

0 Kudos
Message 7 of 13

I see the problem here.  What happens is when you push the stop button, the consumer loop has already operated and has read false from the global variable, so when you set the occurance, the consumer loop iterates and reads false from the global variable.


The loop reads the true the second time, but is waiting on the occurance to happen again.

Message 8 of 13
Accepted by topic author nightwissh

You have a race condition.  So when you set the global to TRUE, the global in the consumer has already been read.  But the loop will not iterate until you generate an occurance.  So now the global has been read as a TRUE, but the loop is sitting ther waiting for yet another occurance.


In general, I find Occurances to be near worthless.  The only place I have found them useful was in an FPGA project.  What you should be doing here is use a Queue.  What you can do with the queue is add data telling the consumer what to do: Increment Count, Reset, Stop.  Do a good search for Queued Message Handler.

There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 9 of 13

Ok thank you for explanation Crossrulz 😉 I managed to do some workaround by adding flat sequence in Consumer loop as you can see in code.

Weird. Occurrences never again 😛



0 Kudos
Message 10 of 13