-
Notifications
You must be signed in to change notification settings - Fork 95
1. Introduction
quantum is a header-only framework using the versatile boost coroutine library under the hood. It implements a high-performance parallel processing engine (akin to a thread pool) for scheduling user tasks as coroutines. All code runs asynchronously and is non-blocking. Since coroutines are cooperative lightweight paths of execution running exclusively in user-space, context switching between them (a.k.a. yielding) is extremely cheap and thus, hundreds of thousands of coroutines can potentially run in parallel at any given time, given enough memory.
Coroutines are similar to threads in the sense that they have their own separate stack and share the process address space. Running a task on the quantum dispatcher is very simple as any callable object type can be invoked. Variables can be passed via lambda captures or as call parameters similar to std::bind
. For long-running blocking IO tasks, a separate thread pool is provided in order to keep coroutine threads from being swapped out by the kernel scheduler. These IO tasks also run in parallel and can send data back to the invoking coroutine thread pool via a future
and promise
pair. Conceptually, this is similar to the std::packaged_task
behavior.
If used properly, most business logic should run inside coroutines, with only a small percentage of code executing blocking IO calls. Examples of such IO could be reading from a database, handling a callback from a third party library or writing to a log file. The coroutine threads never block and as such any blocking task should be dispatched to the IO thread pool. More on that in the following chapters.