取消
显示结果 
搜索替代 
您的意思是: 

Program hangs when stopping consumer loop

已解决!
转到解答

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 😉

0 项奖励
1 条消息(共 13 条)
4,959 次查看

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.



-Matt
0 项奖励
2 条消息(共 13 条)
4,939 次查看

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.  🙂

Bill
CLD
(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 项奖励
3 条消息(共 13 条)
4,937 次查看

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 项奖励
4 条消息(共 13 条)
4,933 次查看

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 项奖励
5 条消息(共 13 条)
4,930 次查看

Remove the occurance in the consumer loop.



-Matt
0 项奖励
6 条消息(共 13 条)
4,928 次查看

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

0 项奖励
7 条消息(共 13 条)
4,924 次查看

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.



-Matt
8 条消息(共 13 条)
4,918 次查看
解答
已被主题作者 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
9 条消息(共 13 条)
4,916 次查看

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 😛

 

occurence-sample.png

0 项奖励
10 条消息(共 13 条)
4,912 次查看