I'm trying to write a function that puts the amount of time in seconds the program has been running into a global variable. I've got one, but it eats CPU time like crazy.
int main()
{
curTime = 0;
DWORD nThreadID;
CreateThread(0, 0, TimeHandler, NULL, 0, &nThreadID);
return 0;
}
DWORD WINAPI TimeHandler(void* a)
{
time_t firstTime;
firstTime = time(NULL);
for(;;)
{
curTime = time(NULL) - firstTime;
}
}
curTime is a global variable.
There must be a better way to do this. Any suggestions on how to decrease the amount of CPU time this takes, or maybe a totally different approach all together?