Skip to content

tsoding/coroutines

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Coroutines

Custom coroutines implementation in GNU C.

What is a Coroutine?

Coroutine is a lightweight user space thread with its own stack that can suspend its execution and switch to another coroutine on demand. Coroutines do not run in parallel but rather cooperatively switch between each other whenever they feel like it.

Coroutines are useful in cases when all your program does majority of the time is waiting on IO. So with coroutines you have an opportunity to switch the context and go do something else. It is not useful to split up heavy CPU computations because they all going to be executed on a single thread. Use proper threads for that (pthreads on POSIX).

Good use cases for coroutines are usually Network Applications and UI. Anything with a slow Async IO.

See coroutine.h for more info. See ./examples/counter.c for a simple usage example in C.

To build the example:

$ make
$ ./build/counter

There are actually much more examples in the ./examples/ in a variety of languages. To build all of them do:

$ make examples

Make sure you have all the corresponding compilers for the languages.

Supported platforms

  • Linux x86_64

More are planned in the future

Special Thanks

This library is heavily inspired by libmill and libdill.

About

Custom coroutines implementation in GNU C

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published