Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Waiting X number of minutes

Status
Not open for further replies.

zub44

Programmer
Dec 18, 2003
7
0
0
US
My question is similiar to the one recently posted about waiting for x milliseconds. I have an idea of how to make a program wait for X minutes, but I would like to hear others opinions or suggestions about how to do this. The following function works, but it continously has the processor checking the time, and Im wondering if there is a better way where the processor does nothing without getting into operating specific functions.


#include <time.h>[/color purple]

void[/color green] Wait_X_Minutes (double[/color green] num_min)
/*Program should wait X minutes without doing anything*/[/color blue]
{
clock_t[/color green] start_time;
double[/color green] lapsed_time;

start_time = clock();
for (;;)[/color red]
{
lapsed_time = (double)[/color green] (clock() - start_time)/CLOCKS_PER_SEC;
if (lapsed_time > num_min*60.0)
break;
}
}


Thanks
Zub

 
Use a non-standard function, like sleep() in unistd.h or Sleep() in windows.h.

Any hard loop type sleep processing is going to be bad for you CPU usage.
 
The suspend() function posted in the "waiting for x milliseconds" could be easily adapted to use seconds as a parameter. I found it nescessary to use that function in my application when one similar to the one you suggest pushed my processor usage to 100%.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top