ITWissen.info - Tech know how online

Coroutine

The language concept of the coroutine (also: coroutine) can be used to express possible parallelisms in the processing of a task. Coroutines are to be regarded as language means for programming quasi concurrency as well as an extension of the procedure concept. The concept of coroutines originated in the use of assembler languages and in programming languages such as SIMULA and Modula-2, which explicitly provide such language elements.

In more recent timeoperating systems with the so-called Thread mechanisms make a similar functionality available for the realization of concurrent programming. Also among other things the programming languageJava was conceived with the background of the development of concurrent software systems with specific language means.

To the fundamental function mode of the principle of a Coroutine:

When a procedure is called, its execution always begins with the first statement; the procedure is then completely processed. The only deviation from this rule are instructions for exceptional situations. Coroutines, on the other hand, can also be processed only partially. A new call causes the execution to be continued at the point of interruption.

A coroutine C can therefore interrupt its execution and leave the program counter to another coroutine. Usually at a later time the program counter will be assigned to C again. It is also said that C gives up control in the meantime. This process is called quasi concurrency. At any time, however, only one coroutine can have control, i.e. be active. After control is relinquished, the values of all local objects are retained, unlike when returning from a subroutine. The state of the coroutine is frozen at the interruption point, so to speak. While between program and subprogram the relationship principal/commissioner exists, a Coroutine is at the same time commissioner and principal. The control transfer happens explicitly, i.e. the assigned Coroutine receives the control directly from the assigning Coroutine.

Coroutines are used primarily in simulation tasks and in system and real-time programming, i.e., in the processing of asynchronously occurring events. However, they can also be used advantageously in other task areas, e.g. as an alternative to recursion.

Informations:
Englisch: Coroutine
Updated at: 06.01.2010
#Words: 350
Links: task, extension (EXTN), procedure, assembler, modular programming language (Modula-2)
Translations: DE
Sharing:    

All rights reserved DATACOM Buchverlag GmbH © 2024