hello guys i havent been on much on MPGH because of school and more.. but i wanted to ask, how i make a delay? like let it wait for 3 secs then continue.... i know its simple but i forgot and im not the one that likes to search =D (I search for different things) i know it was something like Sleep 3; or something i just cant remember
Hmmm... I always had a question about this. Does sleep stop the entire execution from running? Such as if I used sleep in a loop of different functions. Let me show you:
Would the other functions still execute while function 3 is sleeping, because I would imagine they would not and it seems this could cause some problems. if you needed other functions to be regularly updated during the sleep() cycle.
Oh I thought it would be like function 1,2,3 would go then it would wait 3000 and then function 4 would
Originally Posted by why06
You would have to do it like: sleep(3000);
Hmmm... I always had a question about this. Does sleep stop the entire execution from running? Such as if I used sleep in a loop of different functions. Let me show you:
Would the other functions still execute while function 3 is sleeping, because I would imagine they would not and it seems this could cause some problems. if you needed other functions to be regularly updated during the sleep() cycle.
If they're running in the same thread, yes. In simpler terms, if you haven't forked or created a new thread knowingly, then yes it will. I'd explain more but it'd require a whole article on threads, and how Windows does multi-threading.
This is solved by either writing a multi-threaded application, or, instead of performing a sleep, comparing the current time to the last time the function was executed to see if it should execute or just return.
Originally Posted by Jetamay
This is solved by either writing a multi-threaded application, or, instead of performing a sleep, comparing the current time to the last time the function was executed to see if it should execute or just return.
Oh that sounds like a much better idea. I think I made my own sleep function a while back, by accessing the system clock. I never thought to use it to return... o_O
Originally Posted by why06
Oh that sounds like a much better idea. I think I made my own sleep function a while back, by accessing the system clock. I never thought to use it to return... o_O
By return I mean (pseudo code)
Code:
if(lastTimeChk+sleepTime > checkCurTime()) return 0; //End execution of method here
rest of the method's code