R
Rasputin
Is there any way to wait for a particular amount
of time without depending on machine cycles etc?
of time without depending on machine cycles etc?
Rasputin said:Is there any way to wait for a particular amount
of time without depending on machine cycles etc?
Rasputin said:Is there any way to wait for a particular amount
of time without depending on machine cycles etc?
In standard C? You can wait in a loop until time() returns a different
value. That's about it. And you are not guaranteed how often that happens.
For anything "better" (for any definition of the word), use some platform
extensions <OT>such as sleep(), wait() etc</OT>.
Peter
Rasputin said:void sleep( time_t delay )
{
time_t t0, t1;
time( &t0 );
do
{
time( &t1 );
}
while (( t1 - t0 ) < delay );
}
You're right. On any sort of multi-user / mutli-threaded program busy idlingKeith Thompson said:(It wouldn't have been unreasonable, in my opinion, for the sleep()
function to have been included in the C standard, but it wasn't.
Malcolm said:You're right. On any sort of multi-user / mutli-threaded program busy idling
is an unspeakable sin.
Keith said:On the other hand, any system that provides the extensions necessary
to support multi-threading, or even just multiple users or processes,
will certainly provide an appropriate sleep() function. There's
little need for sleep() in portable code; non-portable code might as
well use a non-portable sleep() function.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.