sleep

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Ozguxxx

sleep

Post by Ozguxxx »

Hi people, I just wondered how sleep function can be implemented...
Prototype:
void sleep(int milliseconds)
Thanx....
DarylD

Re:sleep

Post by DarylD »

Have you got a scheduler set up and running? Are you multi-tasking yet?

Daryl.
Ozguxxx

Re:sleep

Post by Ozguxxx »

Nop... Are these really necessary?
DarylD

Re:sleep

Post 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.
Ozguxxx

Re:sleep

Post 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...
jrfritz

Re:sleep

Post 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!
jrfritz

Re:sleep

Post by jrfritz »

That is...it would be a agood idea to freeze that process and not the entire computer.
Ozguxxx

Re:sleep

Post by Ozguxxx »

Thanx for the responses, I found something to not exactly but partially do what I want...
Post Reply