Thread and Class Priorities for Real Time Data in MFC
Posted on 1999-01-29
In a multithreaded MDI MFC app, I load a (non MFC) dll that I wrote which uses _inp and _outp to drive an A/D board. This is used in a university educational physics experiment. The problem is that the time dependent sampling that the card does is apparently interrupted by the multitasking, and the signal becomes "broken" in time. No noise is measured, it's just that the measurement stops and then restarts again,with no data being recorded during the lapse.
The question: How do I suspend all other processes being handled by the os, and instruct it to ONLY run one particular thread? ie, in general turn a Win95/98 computer into a real time data acquisition machine run through an MFC app. The sampling lasts milliseconds to seconds at most.
the "proof" of the problem being the multitasking is that when the mouse is dragged, cpu time is used, and the signal becomes more broken. When the mouse is held still, the signal is "mostly" continuous, but some other threads are still happening apparently..
I believe the best example to use for this is the MTRECALC sample that comes with VC++. In the document class, when the worker thread is begun, I thought this would be the way to do it: setting the ClassPriority and ThreadPriority to realtime for the duration of the calculation:
int prio = GetThreadPriority(m_pRecalcWorkerThread->m_hThread);
//this returns 15
DWORD wrd = GetPriorityClass(CurProc);
//but this returns 256!!
then setting the Class priority back when the thread finishes, to allow for normal program flow.
So, what am I doing wrong? Even during the calculation, the mouse and controls work. I need the cpu dedicated to a specific loop for the duration of that loop, period.
How do I do that?