Thread: sleep()

  1. #1

    sleep()

    What is file do you need to include to use the sleep() function? or are there any other functions better suited for pausing a program?

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    windows.h

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571

    Re: sleep()

    Originally posted by Munkey01
    What is file do you need to include to use the sleep() function? or are there any other functions better suited for pausing a program?
    I'd just like to point out that it is trivial to write your own "sleep" function. All you need is a very basic understanding of timers.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  4. #4
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by vVv
    And I'd just like to point out that I think I know what you're thinking of, and that I guess it'll be a useless (for serious code), ugly kludge.
    See here for an example.
    True, but there are many times where you don't want to pause the process IE if you want other things to go on in your program while the timer is running such as graphics being updated, etc.

    Though, yeah, in the information he provided, sleep is better.

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by vVv
    >I'd just like to point out that it is trivial to write your own "sleep" function.

    And I'd just like to point out that I think I know what you're thinking of, and that I guess it'll be a useless (for serious code), ugly kludge.
    See here for an example.
    There's no need to get ugly about it I just always think its a good exercise to write some things yourself first then use the already existant function call. Another good example of this is all of the string functionality ( i.e. strlen, strcat, etc. ) You'll learn a little more if you do it yourself. Then, knowing the underworkings, you can feel free to use the before-mentioned function. Thats just my opinion though.

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    I believe the point vVv was making is that the home brewed sleep() is, unless done properly, incorrect. By timers you might be refering to windows code which is a bit different, but using timeres in that instance would be a waste I think.

  7. #7
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by vVv
    In that case you'll use threads or more than one process either way.
    Multithreading simply because you want to be able to have a timer going as another part of your program is running is not very wise.

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