Results 1 to 7 of 7

Thread: Bout timers/interrupts

  1. #1

    Thread Starter
    Registered User
    Join Date
    Dec 2001
    Location
    Philippines
    Posts
    13

    Unhappy Bout timers/interrupts

    I want to make a program that will execute a function after 10 minutes. I mean along the process it will pause after ten minutes then execute a certain function. After execution it will resume the other process then count another 10 min. I tried using the delay(); and sleep(); function but it didnt worked. Is there any function that would be this possible?


    ex

    #include <stdio.h>
    main()
    {
    clrscr();
    / * start counting for 10 minutes then execute a certain fxn*/
    /* resume where it stopped */


    }


  2. #2
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    IIRC, sleep() is in milliseconds, so 10 minutes would be sleep(600000);

    If the problem isn't this, please state the problem clearly instead of saying "it didnt worked."

  3. #3
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    You could also use the GetTickCount api.. this example pauses for 10 seconds and then quits:

    Code:
    #include <windows.h>
    
    int main(){
    
    DWORD start = GetTickCount();
    	for(;;)
    		if((GetTickCount() - start) > 10000)
    			break;
    	return 1;
    }
    Alternativly you could use the time functions or as said above, the sleep function...
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    That code will just go round and round and round at 100% CPU.

    Under Windows, calling Sleep(0) will tell the scheduler you don't want any more of your time-slice, hence you can get away with:
    Code:
    #include <windows.h>
    
    int main() {
        DWORD start = GetTickCount();
    
        for(;;) {
            if((GetTickCount() - start) > 10000)
                break;
    
            Sleep(0);
        }
    
        return 0; // return 0 for normal exit, 1 is an error condition
    }
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Thanks for correcting me mike, didn't know about the sleep(0) thing.. ah and also, I always mix up return 1 and return 0 this was the last time hehe (nullrmal )
    Last edited by Jop; Mar 4th, 2003 at 10:23 AM.
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  6. #6

    Thread Starter
    Registered User
    Join Date
    Dec 2001
    Location
    Philippines
    Posts
    13
    Thanks guys! Ill try this one... I'll keep in touch...

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    If you're already using Sleep, why not simply sleep for 8000 ticks and then enter a fast loop? This way you don't even start CPU shifts.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width