🔒 Locked
Making the computer wait
Advertisement
Original Post
Hi guys,
Not an OpenGL question as such, but I''ve always found this forum so informative and helpful in the past...
Basically I need to make a program wait for a certain amount of time, (this time could be < 1 second, or up to 10 minutes) without keeping the processor usage at 99%+ (so continually checking tick count in a loop is not an option). Basically a "resume program running in x seconds" command.
To give you a little extra information...
After a certain time (perhaps even every second/10 secs/minute) the program will either:
a) Perform the next instruction in a pre-stored list
b) check to see the existence of a file. This file will contain the next instructions and will have been saved by a different computer on a shared network drive.
The program will probably just be a console app, but will be one of 2 programs running on that computer and the other prog is quite resource-hungry, hence the need for this prog to not hog the processor...
Any ideas?
Hopefully there''s just a "wait" command or something!...
The function 'Sleep' as it is in the Windows API will actually take its argument in Milliseconds.
So the previous example would be:
IIRC theres a similar function in DOS, that will take its arguments as seconds (sleep(sec)), and one that take milliseconds as an argument (delay(msec)).
[edited by - sphinx23 on March 3, 2004 9:02:26 AM]
So the previous example would be:
// Sleep 10 seconds
Sleep( 10000 );
IIRC theres a similar function in DOS, that will take its arguments as seconds (sleep(sec)), and one that take milliseconds as an argument (delay(msec)).
[edited by - sphinx23 on March 3, 2004 9:02:26 AM]
For unix/linux/etc you''ll want the "sleep(int)" from unistd.h.
I''m virtually positive that takes it''s argument in whole seconds.
It returns an int so you can tell if your program has slept the whole time. If the return value is 0 it''s slept the whole period, if it''s greater than 0 then the value should be the remaining period you wanted to sleep. (It may be revived early if the program gets any signals from the OS.)
I don''t know but I would assume the windows version does something similar.
(Keep in mind that these aren''t guaranteed to be precise. If you need precision timing you''re going to want some sort of real timing code as well. )
I''m virtually positive that takes it''s argument in whole seconds.
It returns an int so you can tell if your program has slept the whole time. If the return value is 0 it''s slept the whole period, if it''s greater than 0 then the value should be the remaining period you wanted to sleep. (It may be revived early if the program gets any signals from the OS.)
I don''t know but I would assume the windows version does something similar.
(Keep in mind that these aren''t guaranteed to be precise. If you need precision timing you''re going to want some sort of real timing code as well. )
sleep means "sleep for around this amount of time". it can sleep for more, it can sleep for less (though i think it usually sleeps for that amount or longer). so DON'T use this as a method of precision waiting.
if you want precision waiting have some kind of timer loop that loops until the right amount of time has passed. or make whatever you're coding event driven so that it doesn't do anything until it receives the appropriate event (if that's applicable to your situation).
[EDIT: ignore the loop part, as i just read your post cerefully and you're not able to use that
]
-me
[edited by - Palidine on March 3, 2004 2:41:10 PM]
if you want precision waiting have some kind of timer loop that loops until the right amount of time has passed. or make whatever you're coding event driven so that it doesn't do anything until it receives the appropriate event (if that's applicable to your situation).
[EDIT: ignore the loop part, as i just read your post cerefully and you're not able to use that
-me
[edited by - Palidine on March 3, 2004 2:41:10 PM]
As far as i know in windows task manager it has a program running called idle procces 93% (93% reading on the cpu) doesnt that mean that whether or not ur actually doing something it is using 100% of the cpu(unless ofcoarse in suspend mode)
Just for intrest sake!! :-)
Just for intrest sake!! :-)
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement