Thread: sleep

  1. #16
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Quote Originally Posted by ulillillia View Post
    Unfortunately, I don't know anything about Unix (never even seen it either) so I can't help you there. Short of using a basic timer system, such as the clock() function, I don't have any other alternatives. For proper use, you'd set a starting time and adjust the current time in a loop and until the difference is what you want, then continue on. Here's some pseudo code to give the general idea:

    Code:
    long StartTime, CurrentTime, EndTime;
    
    StartTime = clock(); // set the starting time
    CurrentTime = StartTime;
    EndTime = StartTime + 2000; // 2000 milliseconds or 2 seconds
    
    while (CurrentTime < EndTime) // loop until the ending time is reached
    {
    	CurrentTime=clock();
    }
    This wastes CPU cycles for no good reason, sleep() and Sleep() exist for a reason

    Stop trying Sleep(milliseconds) suggestions, its for Windows. You want sleep(seconds). But then again, Why do you want to 'sleep' in the first place?
    Last edited by zacs7; 05-16-2007 at 02:55 AM.

  2. #17
    Registered User
    Join Date
    May 2007
    Location
    Colorado
    Posts
    1
    Sorry to jump in, but I'm programming on RedHat Linux and need a sleep function...any ideas what header I would need to include?

  3. #18
    Day Dreamer
    Join Date
    Apr 2007
    Posts
    45
    hi,
    I saw all the confusion about sleep and Sleep.
    Let me clarify, Sleep is a windows function which makes your process wait for a number of "milliseconds" you specify as an argument to it. For using Sleep on windows you need to include windows.h

    However, on Unix/Linux the function is sleep() and it makes your process wait for the number of "seconds" you specify as an argument to it.
    For using it you need to include the header file unistd.h on Unix/Linux.

    sleep() actually makes the current running process wait for the number of seconds you specify.
    I dont really see a reason why your code doesn't wait before the popen.
    If you could put some more of your code, it would be easier for me to know.

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