• Advertisement
Sign in to follow this  

Cooperative Multitasking system

This topic is 1828 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement