solved  how to make a time delay of a few seconds using C++

mathueie (22)   Link to this post

Hi,

I am using ubuntu linux.
How to make a time delay of a more than 30min using C++.
Last edited on
computerquip (876)   Link to this post
...What?

"How to make a time delay of a more than 30min using C++."

It sounds like you want a timer but I'm not exactly sure. :/
Last edited on
writetonsharma (832)   Link to this post
you can use sleep().

it take time in milliseconds.. so calculate how much you need to pass..
it will be around.. (1000 * 60 * 30)
computerquip (876)   Link to this post
I thought sleep only worked in Windows?
kbw (1510)   Link to this post
Sleep is the Windows version, the parameter is milli-seconds.
sleep is the Unix version, the parameter is seconds.
Duoas (3489)   Link to this post
usleep() is the *nix equivalent, the argument is in micro-seconds (10-6).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#if defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(__WINDOWS__) || defined(__TOS_WIN__)

  #include <windows.h>

  inline void delay( unsigned long ms )
    {
    Sleep( ms );
    }

#else  /* presume POSIX */

  #include <unistd.h>

  inline void delay( unsigned long ms )
    {
    usleep( ms * 1000 );
    }

#endif 

http://www.google.com/search?btnI=1&q=msdn+sleep
http://linux.die.net/man/3/usleep

Just to be complete. ;-)
mathueie (22)   Link to this post

Hi


Thanks friends......
Denis (178)   Link to this post
Sorry for late reply

#include <ctime>

inline void mySleep(clock_t sec) // clock_t is a like typedef unsigned int clock_t. Use clock_t instead of integer in this context
{
clock_t start_time = clock();
clock_t end_time = sec * 1000 + start_time
while(clock() != end_time);
}
Last edited on

This topic is archived - New replies not allowed.