LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CVI multi async timer problem

Hi all,
 
I am wondering if anybody has used more than 1 async timer.
 
I use CVI 7.1, created 2 async timer from the main thread using NewAsyncTimer, both Timers have the same configuration. The period is 100ms. Both timer callbacks have the identical contents.
 
However, strange thing is that the timer created first will always have a higher priority, and quite often, the first timer callback is called 2~3 times before the second one is called. Even with release version, it has the same problem.
 
There is no delay(), neither sleep() instructions in the callback. I am wondering if someone has encountered the same problem and would give me a hint. I've stucked almost 3 days on it...
 
Thank you.
0 Kudos
Message 1 of 4
(3,585 Views)

There is another thing that I could not figure out: after some tries, I added some "ProcessSystemEvents" calls to both Async Timer callbacks, but it appears to me that sometimes, when the callback execute this instruction, it goes to the main thread, but after, not back again to the Async Timer callback, and re-enter the Async Timer callback from the beginning. So, after some seconds, it issued an error "general memory protection error", and the program exits.

Thank you again!

0 Kudos
Message 2 of 4
(3,581 Views)
Several years ago I ran into this exact problem.  Before I started coding multiple threads, I figured I could do parallel things using multiple async timers.  What I was told at the time is that even though the documentation for the async timer says it executes in a thread separate from the main thread, if you start two async timers, they both execute in that same separate thread, and they block each other. 
 
My solution was to learn how to program in multiple threads, something very easy to do.  Which is what I would suggest that you do to solve your problem.
0 Kudos
Message 3 of 4
(3,562 Views)
Hi Hendra,
 
thank you for your reply. I came up a bit late, and I had been deeply involved in current project.
 
You are right I did not notice that all the aync timer callback run in a COMMON, seperate thread (I had though 1 for each). The host has to communicate with 2 slaves every 500ms, and the slave is supposed to reply with a delay of around 300ms.
 
As having not known that they share the thread resource, I have put some sleep() instructions in the callback to suspend the thread and obviously the previously described action takes place. Finally I managed to change the code in order that other than making a solo 500ms callback, I divided it into 5x100ms. This approach calmly resolved the problem of delay, without changing much the original code.
 
Still, another point I could not figure out that I got problem when putting the ProcessSystemEvents() in some particular places in the code. I think that it is better to make another post for it.
 
 
0 Kudos
Message 4 of 4
(3,447 Views)