11-18-2011 03:23 PM
I have an application that communicates to multiple devices via individual threads that are essentially running as while(1) loops. Each thread will perform periodic reads to it's device while the writes are handled asynchronously via PostDeferredCallToThread() since the writes are typically generated from a seperate thread. There is also one panel that is updated from the main thread via a PostDeferredCall call. The program runs fine for around 2.5 hours but then all of the post deferred calls stop working. I've run it in both release and debug version with no difference in behavior. The PostDeferredCall*() functions are getting called but the target function that the call refers to is not.
How are post deferred calls queued and is it possible to overflow the queue? I'm at a loss as to how to troubleshoot this. I've searched through the forums and couldn't find anything related. Can anyone offer some suggestions on what I can do to try and figure out what's going on? Thanks in advance.
PS - I'm running CVI 2009 on XP pro
Solved! Go to Solution.
11-19-2011 01:45 AM - edited 11-19-2011 01:46 AM
I cparker,
I have never noted a similar behaviour even in applications I have developed that make extensive use of PostDeferredCall to pass informations between threads. I don't know the size of queues for deferred events, but they can indeed overflow as is noted in this old Knowledgebase entry: nevertheless, this fact causes an error to raise that you shoud note, unless you have masked all error warnings and the error is not a fatal one (besides it, I can imagine the queue is not so limited in space: I am pretty sure the situation described in that KB raises only due to a continuous posting of messages into the queue, a situation that in normal situations should not occurr).
I have had problems in the past when using deferred calls, but every time I ended up finding some other error that was causing misbehaviours: memory leaks, concurrent access to variables or serial ports or so...
Are you sure all deferred calls are honoured until the system stops responding? Could you have a progressive accumulation of unmanaged calls due to very different timing of callbacks (very frequent PostDeferredCall together with slower handling of deferred calls)? Have you some error checking function in your code? Are you getting errors? Which is the rate of PostDeferredCall postings? Can you track down the time spent to handle deferred calls and compare it to the that rate?
11-21-2011 02:51 PM
@Roberto,
Thanks for your response. Per your suggestion, I started looking into the frequency of the post deferred calls and the rate at which they were being serviced. Eventually, I found the culprit and, as you accurately conjectured, it was due to some other error. Long story short, there was an unrelated error that was preventing a state machine from reaching the point to where it processed that thread's system events. All the while, a seperate thread was continually posting deferred calls back to the first thread. Apparently, even though the calls were only every few seconds, a few hours of this was all the system could stand (guessing that it was somewhere around 900-1000 queued calls).
It seems so obvious now that I know what was going on but I think why I was missing it was because the code was in a module that, while running, was not really being used so it was being 'overlooked'. The other thing that was throwing me was that there didn't appear to be anything else wrong. All of the threads were still running/communicating/updating properly, it was only the functions posted to deferred calls (in multiple threads) that weren't functioning.
While I understand what was going on, I still don't understand why it caused all of the other post deferred calls to stop operating. I was under the impression that each thread had it's own queue of system events since we need to process them seperately for each thread. This seems to not be the case if one thread's deferred call overrun causes other thread's deferred calls to not be called.
Either way, your suggestions helped tremendously and I thank you for getting me pointed in the right direction.