Thread: sleep function

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    215

    sleep function

    Im working on this project, and it works fine when I use the sleep function, the only thing is my teacher doesnt want us to use the sleep function, when i use the Wait(NULL) function, it causes the processes to freeze, so instead i was trying to use srand(time(NULL)), but that works sometimes and doesnt work other times. I was wondering if anyone knew any function that I could use instead of the sleep function to delay a process. Im also not allowed to use busy wait loops. My code is also on this site,

    http://sourcepost.sytes.net/sourcepo...ource_id=23770

    and the part where I use srand(time(NULL)) is on line 00100.

    thanks!

  2. #2
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Quote Originally Posted by osal
    so instead i was trying to use srand(time(NULL))
    :blink: What?
    Code:
    if(counter > 0) { 
        for(int l=0;l<counter;l++) {
            srand(time(NULL));
            for(int j=rand(); j; j--);
        }
        wait(NULL);
    }
    What exactly are you trying to accomplish with this code?
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Why do you have to wait in the first place?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Registered User
    Join Date
    May 2004
    Posts
    215
    oh sorry, that wait wasnt suppose to be there, forget the wait, i editted it out in my code, i just forgot to take it out when i pasted it, heres my code again. sorry

    http://sourcepost.sytes.net/sourcepo...ource_id=23771

  5. #5
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    If your instructor doesn't want you to sleep.. they would you be able to wait for another even.. (such as a keystroke) before continuing..??
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  6. #6
    Registered User
    Join Date
    May 2004
    Posts
    215
    Well, the other processes have to finish first and get their turn to receive the message, and then the input prompt should show up again to allow for user input again, so i was thinking the time delay would do it, but it only works some times.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  2. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  3. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 09:10 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM