Plays nicely
A co-routine is a procedure that executes a different part of its task each time it is run. There can be one or more co-routines in progress within a system. Co-routines can be used for simulation programs and routines modeled as finite-state machines.
Co-routines should not prevent other routines from running while they are waiting for something to happen; a routine to wait, sleep, or delay for a period of time (including a time of zero) or to passivate or suspend is usually available.
Rather than using a "return from subroutine" to give up control to the next routine to be run, the co-routine uses a "subroutine call" to a service that saves the return address where the co-routine can find it the next time it is entered (for example, the location preceding the co-routine's entry address). If the co-routine needs to be re-entrant, the data needed across calls, including the return address, can be stored in a "cactus" (branched) stack or on the heap.
If co-routines share a resource such as a data buffer, file, or device they must make sure that two co-routines do not modify the resource concurrently. This usually involves running a sequentialization service (that allows only one process to run at a time). Among the sequentialization services that may be available are semaphores, monitors, and locks.
0 Comments:
Post a Comment
Please enter your comment here. Comments wil be reviewed before being published.
Subscribe to Post Comments [Atom]
<< Home