LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

thread safe queue problem in realtime

Hi,
 
I'm having a problem with a TSQ callback function periodically not firing.  I have data coming into the system via a RS422 interface into a thread.  This thread writes the data into a TSQ.  The TSQ callback wakes up when 10 items are written.  The code usually starts executing OK, but after a few minutes the TSQ callback stops getting called which results in the queue filling up and overflowing.  I have discovered that if I monitor the number of items available in the queue before writing to it, I can flush the queue (if it exceeds the 10 items) and write to it without filling it up.  The callback function will continue not firing for 20 or 30 cycles of flush/write and then start firing again without any particular reason that I can discern.  FYI the size of the queue is 40 items and the callback trigger is 10 items.
 
Any insight into solving this problem is greatly appreciated.
 
Thanks,
Kevin Anderson
Sr. Software Engineer
Lockheed Martin
0 Kudos
Message 1 of 2
(3,052 Views)
Hi Kevin,

One thing I would check is that you don't have some other callback that is taking a long time to return and thereby blocking the event processing.  When you install the TSQ callback, you specify the ID of a thread to execute the callbacks, and in order for that thread to do so, it has to be processing events via RunUserInterface or a loop that calls ProcessSystemEvents.  If you've registered other callbacks to be called from that thread, then it's possible that another callback is being called and is taking its sweet time to return back to the event processing thread so that it can keep doing its job.  If you've got such a situation, then you'll want to change that callback to just signal some other thread to do the real work, possibly by calling CmtScheduleThreadPoolFunction.

I can't think of another reasonable reason for why you'd be seeing that behavior.

Mert A.
National Instruments
Message 2 of 2
(3,050 Views)