Concurrent programming using threads is considered a hard and error-prone task. Coroutines are conceptually simpler, they are easierto program with due to their sequential nature. Flexible coroutines as presented by Belsnes and Østvold liberate classical coroutines from their quasi-parallel world and combine them with threads. This allows the programmer to factor programs into sequential and parallel tasks, leading to simpler programs.
This thesis presents an extension to the formal semantics for flexible coroutines. A detailed breakdown of the scheduling strategies and parameter passing is presented in the same formal framework. Some words are given on patterns that emerge when programming with flexible coroutines and these patterns are defined in the formal framework.
We present a clean implementation of flexible coroutines in Java, based on standard threads and semaphores. Challenges encountered, such as representing coroutines in Java and invoking methods across threads are discussed. This framework is used in examples that employ flexible coroutines in different ways; the classical synchronization problem of readers and writers, the Santa Claus problem and binary and general semaphores.