| ||
Tutorial: Co-routines |
Co-routine sequencing is sometimes considered as a "poor mans concurrency." This is hardly fair, since there is a trade off between the need for concurrency control and the flexibility in synchronization. Co-routines represent the trade-off where synchronization is simple, since "almost everything is a critical region." Using concurrency makes it harder to ensure correct sharing of data, but on the other hand it its sometimes easier to ensure progress in the program as a whole, because some thread will run as long as any thread can do anything. In both cases, the modeling relation sometimes strongly suggests that alternating (co-routine) sequencing or concurrent sequencing is the natural approach to take. After all, the world is massively concurrent! On the other hand, it gets more complicated, or at least less customary, for the programmer to understand what is going on. How does it look?
Both to get co-routine sequencing and concurrent sequencing,
the notion of component is needed. A traditional BETA
syntax for expressing this is the
"|" .
In traditional BETA, the concept of component is at the same level as
the concept of object, i.e. objects and components are fundamentally
different things. In gbeta, the notion of component has been
subordinated the notion of types, and the component properties
(notably the posession of an execution stack) is associated with a
basic pattern called Example 8As an example, we take a very famous algorithm which demonstrates that co-routines is sometimes the most natural expression of alternating processes, a slight variation of the version from Object-Oriented Programming in the BETA Programming Language:
Naturally, the next topic is concurrency. |