in reply to Wakeup: event-loop system
When a program “has nothing to do,” you always want it to explicitly give up control of the CPU, so that other processes can use the CPU. It can sleep for some time-interval, which will give up the CPU during that time, but if it needs to wait “until something happens” then you need to look at things like: signals, semaphores, events, and so-on. With these, the CPU can ignore your program until it truly needs to use the CPU again... an hour from now or a millisecond from now... then resume running it promptly. So the CPU doesn't waste it's time.
Example: in real life, you don't have to constantly pick up the telephone to discover if someone is trying to talk to you. It rings, and (only) then you respond. At all other times you can ignore the phone, and you still won't miss calls.
In any “event-loop” system, the program goes to sleep until the next event arrives. It consumes no CPU resources at all until it has another event to process.
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Wakeup: event-loop system
by fernandes (Monk) on Mar 01, 2009 at 14:10 UTC |