Git Product home page Git Product logo

scoro's Introduction

SCoro

A stackless, resumable, resettable state machine style coroutine library for C++17. This was made when I discovered that C++20 coroutines very frequently require heap allocation and their embodied types are erased.

This does not use C++20 coroutines. It is a managed state machine style coroutine library, a modern take on duffs device. This is suppose to work with C++17 compilers.

Why, because C++20 coroutines:

  • are difficult to develop with.
  • make nested co_await clumbsy and have large memory overhead to do it right.
  • HALO optimization seems to regularly fail.
  • require heap allocation to be avaliable in the general case, making them unusable on many systems.

And:

  • This library allows saving of a SCoro state to a file for later resumption.
  • It allows heap or stack saving of the state, making it easy to use locally or passed to a scheduler or thread.
  • Its lightweight and can be evaluated in constexpr context.
  • Trivially composable (I sometimes find this isn't the case for c++20 coroutines).

Any feedback is welcome, I have a long todo here. I'm looking at improving the actual standard C++ coroutines eventually with a similar approach. If anybody sees advantages and disadvantages of my approach I'd love to hear about them!

The ultimate idea is to have the language be syntactic sugar around this sort of pattern.

To boost the algorithms generality I'd love requests for examples, that I can put in the git. The examples would need to be cross platform, so that limits things a little (most async ops are connected with OS or hardware). But any ideas I'll add an example.

Examples in library:

  1. composition, with nested SCoro's and reusable SCoro blocks.
  2. timing, an example that deals with polling of a scheduled event, something like a wait_for.
  3. continuing on a different thread than the initiating thread.
  4. iota example.
  5. C++20 coroutine integration example (very basic)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.