Cooperative Multitasking system

Started by
1 comment, last by rik_GT 11 years, 2 months ago

Hi there

I'm trying to get around the concept of cooperative multitasking system and exactly how it works in a single threaded application.

My understanding is that this is a "form of multitasking in which multiple tasks execute by voluntarily ceding control to other tasks at programmer-defined points within each task."

So if you have a list of tasks and one task is executing, how do you determine to pass execution to another task? And when you give execution back to a previous task, how do resume from where you were previously?

I find this a bit confusing because I don't understand how this can be achieve without a multithreaded application.


Any advice would be very helpeful :)

Thanks

Advertisement
Generally speaking, each unit of execution in a cooperative multitasking system still has it's own stack. The context switch mechanism preserves the stack for each unit of execution. For example, in Windows you can use cooperative multitasking via the fiber API. Switching to a different fiber is as simple as just calling the SwitchToFiber() function. How to figure out when to switch to another unit of execution depends on how you want the units of execution to share processing time; it's situation specific rather than one size fits all.

Thanks for pointing out the fiber API ;)

Will have a look.

Thanks

This topic is closed to new replies.

Advertisement