Efficiency of reading data threads and timers from PCI
Thread:
Mythread = afxbeginthread (startcontinuous, (lpvoid) 1, thread_priority_normal, 0, create_suincluded );
Mythread-> resumethread ();
Uint startcontinuous (lpvoid pparam)
{Hwnd = (hwnd) pparam;
Int Len = 0;
File * FP;
I = 0;
While (threadenable)
{
Len = cpci6312_readdata (BUF );
If (LEN> 0)
{
Reccnt + = Len;
Fwrite (BUF, 1, Len, FP );
}
}
Len = cpci6312_readlastdata (BUF );
If (LEN> 0)
{
Reccnt + = Len;
Fwrite (BUF, 1, Len, FP );
}
Fflush (FP );
Fclose (FP );
Afxmessagebox ("end", mb_ OK, null );
Return 0;
}
Counter method:
Void cdemo2dlg: ontimer (uint nidevent)
{
// Todo: add your message handler code here and/or call default
If (nidevent = 1) // update Record Data
{
Runsec ++;
Str. Format ("record: % d (% d)", reccnt, runsec );
M_list.addstring (STR );
}
If (nidevent = 2) // collect data
{
Len = cpci6312_readdata (BUF );
If (LEN> 0)
{
Reccnt + = Len;
Fwrite (BUF, 1, Len, FP );
}
}
Cdialog: ontimer (nidevent );
}
With the same data volume, the thread method actually occupies more than 80% of the CPU, and the counter is less than 30%.