Thread: sleep

  1. #1
    Registered User ivandn's Avatar
    Join Date
    Oct 2001
    Posts
    49

    sleep

    Hi,

    I am trying to sleep in my program for a half second.

    sleep(1) appears to sleep for a second and sleep(.5) appears not to sleep at all.

    I am doing this wrong or is there another way to sleep for partial seconds?

    thanks
    Ivan

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You could try usleep(500000);
    to sleep for 500000 microseconds.

    But bear in mind, it's still a minimum value - the operating system might decide there are more important things to do when the time is up.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    A Banana Yoshi's Avatar
    Join Date
    Oct 2001
    Posts
    859

    or...

    be cheap and use the for() statement
    Yoshi

  4. #4
    Unregistered
    Guest

    Re: or...

    Originally posted by Engineer223
    be cheap and use the for() statement
    How are you supposed to 'sleep' using a for() statement?!

  5. #5
    Registered User cody's Avatar
    Join Date
    Sep 2001
    Posts
    86
    by using an empty for statement

    aloa
    cody
    #include "reallife.h"

  6. #6
    How do you know how long one for() loop lasts?
    What will people say if they hear that I'm a Jesus freak?
    What will people do if they find that it's true?
    I don't really care if they label me a Jesus freak, there is no disguising the truth!

    Jesus Freak, D.C. Talk

    -gnu-ehacks

  7. #7
    Registered User cody's Avatar
    Join Date
    Sep 2001
    Posts
    86
    You don't
    That's why it's cheap

    aloa
    cody
    #include "reallife.h"

  8. #8
    A Banana Yoshi's Avatar
    Join Date
    Oct 2001
    Posts
    859
    Or include the <time.h>
    Do you have one?
    Yoshi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [pthread] cancellable sleep in win32?
    By cyberfish in forum C++ Programming
    Replies: 2
    Last Post: 08-11-2007, 02:30 AM
  2. Sleep works with just one thread, but not 2
    By finkus in forum C++ Programming
    Replies: 5
    Last Post: 12-01-2005, 09:17 PM
  3. Problem with Sleep() #$@^#$%^
    By intruder in forum C++ Programming
    Replies: 8
    Last Post: 10-11-2004, 06:46 AM
  4. why do we require sleep?
    By jinx in forum A Brief History of Cprogramming.com
    Replies: 43
    Last Post: 07-14-2004, 08:21 AM
  5. Sleep is overrated...
    By Polymorphic OOP in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 01-24-2003, 12:40 PM