LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using Queues with Event Structures

Is there a way to have a queue create an event when a message is present in the queue using an Event Structure?  I am burning CPU because I am polling the queue to see if it has any data and I need a quick response.  I have other events I am looking for so using the Event Structure would be preferred over using a Wait on Event implementation.  I have thought of using a Notifier that would be set when a message is put into the queue.  Open for some ideas.
 
This is a multithread implementation where multiple threads are adding data to the queue and one thread is pulling data off of the queue.
 
Thanks,
 
Matt

Message Edited by mfitzsimons on 11-11-2005 12:15 PM

Matthew Fitzsimons

Certified LabVIEW Architect
LabVIEW 6.1 ... 2013, LVOOP, GOOP, TestStand, DAQ, and Vison
0 Kudos
Message 1 of 11
(4,467 Views)
Create a boolean flag.  Create an event case on the flag's value (signaling) event.  Anytime you post a message to the queue, invert the flag's value (you can use local variables here).  Everytime the flag changes, you will fire the new event and you can put code inside the event case to read the queue.
- tbob

Inventor of the WORM Global
Message 2 of 11
(4,452 Views)

tbob,

Sounds simple enough.  Do I have to be concerned about a potential race condition?  If two events fire at the same time do I get one event or two?   Thanks for providing a simple solution to a complex problem.

Matt

Matthew Fitzsimons

Certified LabVIEW Architect
LabVIEW 6.1 ... 2013, LVOOP, GOOP, TestStand, DAQ, and Vison
0 Kudos
Message 3 of 11
(4,445 Views)
If you are writing to the queue at several different places and the processes run in parallel, then you might have (probably will have) a race condition.  But if this is so, your queue will have a race condition also, no telling which element was put in the queue first between two parallel processes.  I would have just one queue manager (subvi) and let different processes make calls to the queue manager to put their elements in the queue.  You could use a semaphore to allow only one process at a time to call the queue manager.  Inside the queue manager is where you would put the flag inverting code to cause the event.  This way there would be no race conditions.
- tbob

Inventor of the WORM Global
Message 4 of 11
(4,432 Views)

Hi Matt,

      Very clever tbob! (gonna remember that one...)

      Just out of curiosity, why is it burning CPU to poll queue?  I though the Dequeue timeout made it very efficient...

?

Message Edited by Dynamik on 11-13-2005 01:02 AM

Message Edited by Dynamik on 11-13-2005 01:04 AM

When they give imbeciles handicap-parking, I won't have so far to walk!
Message 5 of 11
(4,401 Views)
darn, i'm sooo sloow
 

Message Edited by Dynamik on 11-13-2005 01:07 AM

When they give imbeciles handicap-parking, I won't have so far to walk!
Message 6 of 11
(4,395 Views)
The characters of text on buttons cannot be underlined individually.  Someone please justify this.
 
I want to underline one of the characters of the boolean text in buttons. It does so. But whwn the VI is reopened the entire text is underlined. ????? How to get out of this?
 
 
0 Kudos
Message 7 of 11
(4,365 Views)
Dynamik,
 
The issue with Wait for Dequeue in my case is that I also need to look for other events in that thread.  So If I wait 5 seconds for dequeue I can not process other events.  With tbob's solution I only run the thread when information is in queue and I can process the other events quickly.  One further simplification is that I am not inverting the state when I use value (signaling) because any information written will generate an event.
 
Not sure why ritu has joined into this discussing.  Mispost?
 
Thanks for all of your help,
Matt (aka mfitzsimons)
Matthew Fitzsimons

Certified LabVIEW Architect
LabVIEW 6.1 ... 2013, LVOOP, GOOP, TestStand, DAQ, and Vison
0 Kudos
Message 8 of 11
(4,340 Views)
Hi Ritu,
 
In the future, please post new issues in new threads.  This way it will be easier for other users to find and reply to your posting.  The way buttons currently work, there is no way to have two different font runs on a single button.  This is true even for LabVIEW 8 and has to do with the way the buttons are programmed.  If you would like to give feedback to our developers, I strongly suggest submitting a product suggestion at our Product Suggestion Center: http://digital.ni.com/applications/psc.nsf/default?openform.  Our R&D developers really do look at all the product suggestions.
 
Megan B.
National Instruments
0 Kudos
Message 9 of 11
(4,310 Views)
thanks - should'a realized that's what you meant by "I have other events I am looking for"...
When they give imbeciles handicap-parking, I won't have so far to walk!
0 Kudos
Message 10 of 11
(4,304 Views)