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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TImer in c or c++

Status
Not open for further replies.

Vallurupa

Programmer
Oct 17, 2001
38
US
I want to wait some time in my while loop.
How is write
timer in my while loop.

int flag=1;
while(flag==1)
{
for(int i=0;i<=500000000;i++)
{
}
//i have to replace timer with this for loop
//My code
//

}

please help me

thanks
 
Go to sleep :)...

use Sleep function, if you are working under Windows. There is something similar in unix too, but I can't remember the function name... Could be the same, or delay() or something like that. [red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...
once stated: methane@personal.ro
 
You have a while loop, ending only if flag != 1.
Is flag set to semething else in the code after the wait function? In that case you must use Sleep ( ) to wait, like Nosferatu suggested.
But, if flag is set to semething else by a different thread, it might be better to use some of the synchronisation API calls, like a critical section or a mutex.

Marcel
 
If you are writing a single-threaded program, use Sleep fn to wait a specified number of milliseconds.

If you are writing a multi-threaded program do not use Sleep as it could cause all threads to sleep, rather, use the WinNT timeSetEvent() fn.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top