Glossary · Automation software engineering and architecture
Coroutine
German: Koroutine
In programming, a coroutine is a routine that can suspend its execution at defined points and later resume from where it stopped, keeping its local state, which allows several activities to be interleaved cooperatively within a single thread.
- Software engineering
In one sentence
A coroutine can suspend execution at defined points and resume later with its local state, enabling cooperative interleaving.
Example
An edge application uses coroutines to wait for responses from 50 devices concurrently in one thread, instead of starting one thread per device.
How it applies
- Engineering: Coroutines, often written with async/await syntax, suit I/O-bound work such as network communication, where most time is spent waiting. They avoid the overhead and locking complexity of many threads.
- Automation context: PLC programs do not use coroutines directly, but the idea is similar to step sequences: a sequence waits in a step and continues in a later cycle. Edge applications, gateways and test tools written in Python, C#, C++ or Kotlin often use coroutines.
- Documentation: Developer documentation should state which functions are asynchronous, what they may wait for and how cancellation and Timeout handling work. Blocking calls inside a coroutine stall all others in the same thread, a common and hard-to-diagnose error.
Coroutine vs. thread
Threads are scheduled by the operating system and can run in parallel or be preempted at any time. Coroutines switch only at explicit suspension points and run within one thread unless the framework distributes them. Coroutines are a form of Cooperative scheduling.