© Thomas Kunz 2000
SCE 574
185
Concurrency:
Co-routines
äCo-routines, a simple strategy
äWhen the current activity is ready to transfer control it:
äSaves its context locally
äContext includes: registers including the stack pointer, base pointer, instruction pointer, flags etc..
äBranches to an entry point of the next routine
äThe first instructions of the called routine restore its context then resumes execution
äThe schedule is often well defined and hard coded
äCould also use an intermediate routine to implement a scheduler
äCo-routines with a user implemented scheduler
Restore Context
Branch to old IP
Save Context
Branch to sched
Save Context
Branch to sched
Context storage area
Restore Context
Branch to old IP
Save Context
Branch to sched
Save Context
Branch to sched
Context storage area
Restore Context
Branch to old IP
LOOP:
Save Context
Branch to A
Save Context
Branch to B
END LOOP:
Context
storage area
A
Sched
B