Page 1 of 1
sleep
Posted: Wed Dec 18, 2002 7:40 am
by Ozguxxx
Hi people, I just wondered how sleep function can be implemented...
Prototype:
void sleep(int milliseconds)
Thanx....
Re:sleep
Posted: Wed Dec 18, 2002 7:58 am
by DarylD
Have you got a scheduler set up and running? Are you multi-tasking yet?
Daryl.
Re:sleep
Posted: Wed Dec 18, 2002 8:36 am
by Ozguxxx
Nop... Are these really necessary?
Re:sleep
Posted: Wed Dec 18, 2002 8:41 am
by DarylD
Well, sleep() is not much use in a single tasking environment as its task is to halt execution of the currently running task/thread and switch to another ready one.
Basically, sleep works as follows:
1. Process calls sleep(time)
2. Kernel changes the state of the task from running to sleeping.
3. It sets a timeout value based on the number of times per second the timer interrupt occurs.
4. It then switches to another ready task and executes away.
5. On the next timer interrupt it decrements the timeout value. If this value is now zero (i.e. the sleep time has passed) it sets the task to ready and will execute again shortly.
So, without a scheduler or multi-tasking it won't do very much!!
If you just wan't to freeze execution, well there are various ways of doing this, including counting timer interrupts and using a counting loop.
Daryl.
Re:sleep
Posted: Wed Dec 18, 2002 10:19 am
by Ozguxxx
Yes, I just want to freeze execution and wait for floppy motor to spin up... On the net people do this by some kind of sleep function but I could not find implementation of the functions...
Re:sleep
Posted: Wed Dec 18, 2002 10:29 am
by jrfritz
That wouldn't be a good idea...Linux doesn't freeze when reading a floppy...if you did that you'd have a OS like Win3.1!
Re:sleep
Posted: Wed Dec 18, 2002 11:49 am
by jrfritz
That is...it would be a agood idea to freeze that process and not the entire computer.
Re:sleep
Posted: Wed Dec 18, 2002 4:49 pm
by Ozguxxx
Thanx for the responses, I found something to not exactly but partially do what I want...