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 😉
Solved! Go to Solution.
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.
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. 🙂
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."
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.
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.
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.
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 😛