Sign in to follow this  
rik_GT

Cooperative Multitasking system

Recommended Posts

rik_GT    126

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

Share this post


Link to post
Share on other sites
SiCrane    11839
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this