sleep() problem when Time Hits Midnight

This is a discussion on sleep() problem when Time Hits Midnight within the C Programming forums, part of the General Programming Boards category; Code: Hi all, I want to make my application to sleep for a second so i have implemented it with ...

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    2

    Unhappy sleep() problem when Time Hits Midnight

    Code:
    Hi all,
    
    I want to make my application to sleep for a second so i have implemented it with
    static void
    sleep(int iSecs)
    {
    	int iCount=0;
    	unsigned long int t=clock()+(1000L*iSecs);
    	while(clock()<t)
                          ;
     }
    which is working fine. The problem comes when  the Time hits to 11:59:58 PM
    the clock() reduces to 0 n mean while t has reached maximum value as a result this while loop is going too long n making my program halt for more than 30 min.
    How do i come out from this problem? Is ther any subsitute solution for sleep() which supports with 16 bit compiler

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    > which supports with 16 bit compiler
    Which one?

    I'm going to guess you also have a delay() function somewhere which could be used in place of that while loop you have.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    2

    Question sleep() Problem when time Hits midnight

    Code:
    i have tried with it but the compiler is not Supporting that...
    
    it has undefined i have used dos.h header also.....
    
    
    then i tried breaking the loop for so much of count
    while(clock()<t)
        {
    		iCount++;
    		if(iCount>15000)
    			break;
    }
    
    Its working fine now. But can i consider this solution as a standard programming solution?

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Since you refuse to say which compiler you're using, so you can get a better answer, I guess we're done.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,296
    Ironically, in most operating systems your sleep function will do anything but let the processor sleep. To the contrary it will make the processor busier and hotter than ever.

    It will however block execution for the required length of time in most cases.

    can i consider this solution as a standard programming solution?
    No, quite the opposite actually.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with time program
    By rushhour in forum C++ Programming
    Replies: 4
    Last Post: 02-05-2009, 07:39 AM
  2. problem with my time code
    By dol.beers in forum C++ Programming
    Replies: 1
    Last Post: 10-21-2008, 01:37 PM
  3. Sleep problem
    By GARGONII in forum C++ Programming
    Replies: 5
    Last Post: 03-29-2002, 09:58 PM
  4. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 09:12 PM
  5. Simple Compile Time Problem - HELP!
    By kamikazeecows in forum Windows Programming
    Replies: 2
    Last Post: 12-02-2001, 12:30 PM

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