Additional Information
When you call the
LabWindows/CVI Delay
(double Number_of_Seconds)
function, LabWindows/CVI waits for the specified number of seconds before executing the next line of code. However, this is a "busy wait" loop in which the CPU is utilized 100%.
On the other hand, the Windows SDK includes the
Sleep(long dwMilliseconds)
function, which suspends the execution of the current thread for a specified number of milliseconds. This yields the CPU to other threads and processes, so the current LabWindows/CVI application thread does not tie up the computer's CPU.
You can demonstrate this behavior by running the following sample code as a LabWindows/CVI console application. On the test machine (Pentium III 1GHz, 256MB RAM), the CPU utilization was at 100% during the
Delay(0.01 sec)
function and at about 10% during the
Sleep(10 ms)
function:
#include <windows.h>
#include <ansi_c.h>
#include <utility.h>
int main (int argc, char *argv[])
{
int i=0;
printf("delaying 10ms (watch CPU)...\n");
for (i=0; i<1000; i++) {
Delay(0.01);
}
printf("sleeping 10ms (watch CPU)...\n");
for (i=0; i<1000; i++) {
Sleep(10);
}
return 0;
}