A thread support library which supports coroutines and channels.
C++ CMake
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Somnus is a co-operative threading support library (See: Fiber).

Fibers are a powerful concurrency tool that prevents unnecessary blocking and operating system thread context switching. It's not a panacea, but it is a useful tool which, utilized in the proper way, yields massive performance gains.

Refer to the wiki for type and function documentation.

Channel Examples

The canonical example of any coroutine based model is an example with a channel. The following two examples show the use of a channel for both pointer types and non-pointer types.

Non pointer type example

Pointer type example

std::shared_ptr type example

Event Dispatch Examples

An event dispatcher class is supplied along with the other functionality of the library. It uses Ropes internally based upon a configuration loaded from a file.

Event Dispatcher Example

Configuration File Example

Other Examples

Long running tasks prevent other tasks from doing useful work, including initiation of long running operations. To prevent this, long running tasks should carefully place calls to defer() which switches to other waiting tasks, if needed. Execution will resume after all other waiting tasks have had an opportunity to run.

Defer Functionality