Re: Multitasking: active waiting!?
- Posted by Robert Craig <rds at RapidEuphoria.com> Apr 18, 2006
- 467 views
Ryan W. Johnson wrote: > Rob: I tried the new multitasking routines, and i realized that the CPU is at > 100% even though the tasks are not running all the time. Here is how i set up > the scheduling: > > }}} <eucode> > task_schedule(task_kernMain_HighPri, {0.005, 0.01}) > task_schedule(task_kernMain_LowPri, {0.5, 1}) > task_schedule(task_kernMain_100ms, {0.1, 0.1}) > task_schedule(task_kernMain_500ms, {0.5, 0.5}) > task_schedule(task_kernMain_1s, {1, 1}) > task_schedule(task_kernMain_2s, {2, 2}) > task_schedule(task_kernMain_10s, {10, 10}) > task_schedule(task_kernMain_60s, {60, 60}) > }}} <eucode> > > Even if i change the first line to {0.5, 1} it still maxes the CPU. Shouldn't > euphoria allow the program to sleep between tasks, even if only for 0.01 > seconds? I just cannot use this if it's gonna how the CPU! The way it works at the moment, the Euphoria task scheduler calls sleep() only when there is a gap of at least 1 second until the next task is due to resume. That's because sleep() only has a resolution of 1 second (that's the worst case across all platforms). For smaller gaps it just spins its wheels in a loop. It might be wasteful to sleep for a tiny fraction of a second, giving up control, and hoping the O/S will give it back in time. Also, other than DOS, the O/S should be able to grab control pre-emptively whenever it wants to run another process, regardless of whether you are sleeping or not. > This brings up another point that i meant to bring up a long time ago: > could you change sleep() so that it could have a higher resolution, such as > 0.01 seconds? Yes, I would like to have a higher-resolution sleep(), and I will look into it. I don't think all the various C compiler libraries provide that directly though. Thanks, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com