PDA

View Full Version : write own sleep or delay function c++



asylu3
25-03-2004, 09:45 PM
#include < time.h >
#include < iostream.h >

void sleep( clock_t wait )
{
clock_t goal;
goal = wait + clock();
while( goal > clock() );
}

void main()
{
sleep(5000);
cout<<"hello";

}

Note: this code implemented in vc++ 6.0

asylu3
21-04-2004, 02:06 PM
This one would helpful also.


#include < iostream.h >
#include < windows.h >
void main()
{

cout<<"test";
::Sleep(1000);
cout<<"test2";
}

ar3s
23-09-2004, 01:13 PM
The ::Sleep() function in not a delay function for everything. It is only to suspend the execution of the current thread for a specified interval.
In other words the time in this function is controlled by the current thread priority.