Suppose I have C ++ code like
#include "myheaderfiles.h"
int main()
{
double milliseconds;
int seconds;
int minutes;
int timelimit=2;
...
...
while(minutes <=timelimit)
{
if(milliseconds>500)
{
}
}
}
The program will work fine and does what it should do, but it will use 90% + of my processor.
I was asked to use usleep () in my while loop of 100 ms or so, since I really care about doing things every 500 ms anyway. Thus, it starts the processor when it is not needed.
So, I added it to my while loop so
while(minutes <=timelimit)
{
if(milliseconds>500)
{
}
usleep(100000);
}
It compiles fine, but when I run it, the program will hang right at home and never return. I read somewhere that before calling usleep you need to flush all buffers, so I blushed all file streams and replicas, etc. Etc. Still out of luck.
2 . (), .
, , , , .
while(), , , FPGA, .
- ... , , ? .