07-13-2006 09:16 AM
07-13-2006 09:50 AM
07-14-2006 04:31 AM
07-14-2006 08:45 AM
07-14-2006 10:10 AM
I'm not familiar with Thread Safe Queue Callbacks in particular, but if they work in a similar manner to other types of CVI callbacks I think their action is triggered by the ProcessSystemEvents() function. This probably means that you will need to call ProcessSystemEvents() at a faster rate than the callbacks can be generated, to ensure that you do not miss any of them and that a backlog does not build up in the queue. I tend to use a Timer control set to 0 seconds and use its callback to call ProcessSystemEvents(), to make sure it gets called whenever CVI has nothing better to do. Perhaps an alternative approach for you would be to put a ProcessSystemEvents() call at the very end of your ProcessDataTsqCB() function, so that if another packet was pending in the queue it could be handled immediately. You should code the function to be re-entrant, in this case.
Also bear in mind the granularity of the Windows timer used for the Sleep() function; in my experience this is usually 10 or 15 ms depending on the PC hardware configuration, meaning that if you ask for between 1 and 10 (or15) you will always get 10 (or 15). Caught me out once when I had Sleep(1) in a timeout loop - this turned out to take15 times longer than I expected.
JR
07-14-2006 10:24 AM
07-16-2006 07:58 PM
Here is an approach that avoids TSQ and ProcessSystemEvents() issues:
Remember to call CmtDiscardThreadPool() when you're done.
Regards,
Colin.
07-19-2006 08:47 AM
Another way to get your thread to release resources back to the OS but still maintain a pretty good response time to events is to use the MsgWaitForMultipleObjectsEx() found in the windows SDK. This avoids some of the issues with Delay() and Sleep().
A generic example:
HANDLE hWndThread;
hWndThread=(HANDLE)GetCVIWindowHandleForCurrentThread();
while (whatever_makes_you_loop_stop != true)
{
MsgWaitForMultipleObjectsEx(1, &hWndThread, 500, QS_ALLEVENTS|QS_ALLINPUT, MWMO_ALERTABLE);
ProcessSystemEvents();
}
You can play around with various settings of MsgWaitForMultipleObjectsEx() if you know which types of windows events you want to wake your thread up. You do not need to call ProcessSystemEvents() if the thread does not do anything directly related to a CVI event. This is also a very useful way to put a thread to sleep while another thread completes some action.
More on this very flexible function can be found at the MSDN website http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/msgwaitformultipleobje....