Sleep()? What does it do?

This is a discussion on Sleep()? What does it do? within the C++ Programming forums, part of the General Programming Boards category; I have a question about the function sleep();. I need to know what exactly it does. Does it just freeze ...

  1. #1
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719

    Sleep()? What does it do?

    I have a question about the function sleep();. I need to know what exactly it does. Does it just freeze the computer for a certain time? Or are you allowed to do stuff while it is sleeping? Ex. What I want to do is use sleep(); to put a time constraint on the user. But still allow the user to go about the screen. But when the time is up it goes to another function. Could this be done?
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    The windows version of Sleep simply freezes the thread that enters the function. Other running threads arent affected

  3. #3
    Banned
    Join Date
    Jun 2005
    Posts
    594
    Short Answer, it pauses the thread for the number of milliseconds,
    that you choose.

  4. #4
    Registered User mitakeet's Avatar
    Join Date
    Jun 2005
    Location
    Maryland, USA
    Posts
    212
    If you do not put your interface on a separate thread, then it will 'freeze' until the Sleep has expired.

    Free code: http://sol-biotech.com/code/.

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

  5. #5
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Ok. I got it now.Thanks.
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  6. #6
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Be careful calling Sleep() within Windows programs, especially those that are call Sleep() from the same thread as the message handler for the user interface. If your program does not check for messages for 5 seconds, Windows will decide it is unresponsive, so Sleep() can be dangerous. It's probably better to use SetTimer() if you need to delay for more than a few milliseconds.
    Away.

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, 03: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, 07: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, 09: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21