??? 08/07/08 12:47 Read: times |
#157297 - Super-loop contra cooperative multitasking Responding to: ???'s previous message |
Your description of cooperative multitasking is actually a description for a super-loop.
In cooperative multitasking, you do have individual tasks with their own stacks - just as in preemptive multitasking. It's just that you do not have a timer that slices the time between the tasks. Instead, you sprinkle your code with function calls to tell the OS that this is a safe/suitable place to perform a switch. Windows 3.1 for example used cooperative multitasking. Real programs with their own stack. But if one program got stuck and stopped to call any switchable Windows function, everything got stuck. In short, in cooperative multitasking, you do not need any state machines, since each task has a stack and it's own set of local variables. The reason for cooperative multitasking is when you have OS calls, or RTL functions that are not preemptive. Then you can't let a timer perform the task switch, since the task switches will not be synchronized with regard to dangerous functions. So cooperative multitasking is almost as problematic for the 8051 architecture as preemptive multitasking. That leaves the developer with super-loops and creative use of interrupts. |