LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Queue Not Working as expected!

Solved!
Go to solution

I am working on a program and I've encounter rather wired behavior for Queue in labVIEW. I attached a simplified version of my VI.

 

the data from Queue is somehow clear data coming from other loop. I define two identical queues to show the problem. the size of the lists is different!

Download All
0 Kudos
Message 1 of 10
(3,175 Views)

Your code is perplexing.

 

  1. In your top-loop when you dequeue from Queue2, you do not put the message in any string indicator.
  2. You have a bunch of property nodes, each requires a UI thread, there is only one UI thread, that is going to cause a bunch of your loops to pause and wait until the thread is available. Once the thread is available you have no idea which loop is going to grab it.

Maybe it would be better to explain what you are trying to do.

 

mcduff

0 Kudos
Message 2 of 10
(3,159 Views)

 

  1. In your top-loop when you dequeue from Queue2, you do not put the message in any string indicator.
    Yes I used dequeue just for iteration. If I used the dequeued message from queue 2 I will get the same results. I wanted to show the difference.
  2. You have a bunch of property nodes, each requires a UI thread, there is only one UI thread, that is going to cause a bunch of your loops to pause and wait until the thread is available. Once the thread is available you have no idea which loop is going to grab it.
    Maybe it would be better to explain what you are trying to do.
    In simple form, the program sends and receives messages from a serial ports. I defined a loop that read the serial port and put it as a string  in a queue. there is another while loop which dequeue the string and put it in a string indicator. The user also send messages to serial port. So there is another event structure that send to serial port. I use same string indicator to show sending messages too.to have access to the string indicator I used property node in all this loops to access the string indicator. But when a string comes from serial port what user send in string indicator will be deleted.

 

0 Kudos
Message 3 of 10
(3,150 Views)

You are reading and writing to property nodes and terminals of the same controls in parallel in different loops, causing serious race conditions. This cannot end well.

 

What's the purpose of this exercise? What are you actually trying to do?

 

Message 4 of 10
(3,134 Views)

You are reading and writing to property nodes and terminals of the same controls in parallel in different loops, causing serious race conditions. This cannot end well.

 

What's the purpose of this exercise? What are you actually trying to do?

 

Yes I also believe it is a form of race condition but how I can solve it? (by the way I've used local variable same problem).  I am trying to update the same string indicator is updated in several places. I think queue is thread safe so it must be  string indicator.  I plan to use semaphore to see if it is the problem. What is your suggestion?

0 Kudos
Message 5 of 10
(3,125 Views)

  I am trying to update the same string indicator is updated in several places.

 

Queues can work N to 1, that is, use multiple instances of the same queue to update the indicator. (In this case you dequeue only in 1 place)

 

mcduff

Message 6 of 10
(3,122 Views)
Solution
Accepted by topic author Dr--X

Use an action engine to maintain each list. Keep it in a shift register, no locals or value properties needed. The non-reentrant nature of the action engine protects from parallel access.

Message 7 of 10
(3,114 Views)

I am not quite sure what do you mean by Queues can work N to 1. I defined another queue and put string related to the string indicator in it and dequeue it in one places and updated the string indicator in the same place as you suggested and it solves my issue.

0 Kudos
Message 8 of 10
(3,112 Views)

Assume multiple parts of your code update your indicator in different places. Use the same queue in those places, so you have “N” enqueue operations and you dequeue at once place, hence N to 1.

 

mcduff

0 Kudos
Message 9 of 10
(3,097 Views)

@Dr--X wrote:

 In simple form, the program sends and receives messages from a serial ports. I defined a loop that read the serial port and put it as a string  in a queue. there is another while loop which dequeue the string and put it in a string indicator. The user also send messages to serial port. So there is another event structure that send to serial port. I use same string indicator to show sending messages too.to have access to the string indicator I used property node in all this loops to access the string indicator. But when a string comes from serial port what user send in string indicator will be deleted.


What I would do is use a User Event to send a message to your Event Structure (GUI loop) for updating the indicator.  You can send that event from anywhere and it will update in the order in which messages were sent.


GCentral
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 10 of 10
(3,063 Views)