GithubHelp home page GithubHelp logo

tisan2021 / coroutines Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yabadabu/coroutines

0.0 1.0 0.0 128 KB

Coroutines in C++. (Currently only on windows using Fibers API)

License: MIT License

C++ 100.00%

coroutines's Introduction

This is a C++ wrapper on top of libCouritines

- Move TChannel to handle-based resource
+ TimeOut

- A co is:
  - Running, meaning will run until yields or checks a wait condition
  - Waiting for events we control
    - Reading data from a channel, and now there is data in the channel
    - Writing data to a channel, and now there is space in the channel
    - Waiting another co to finish
  - Waiting for time
    - Sort co's waiting for time events, sorted by waiting time. Each time
      we tick, dispatch those surpassed by the time. A co could be waiting
      for data in a channel and waiting for time -> 
  - Waiting for user defined conditions which need to be checked/poll on every tick
  - Waiting for I/O,Net operations
  - Allow user to create his own events, which when triggered will wake up
- Implications
  - A channel must known which co's are waiting for data in the channel
  - A channel must known which co's are waiting for space in the channel
  - A co must known who is waiting for him. And wake up when dies.
  - There is a list of co waiting for time events
  - A co could be waiting for several channels events and a timeout
- When a channel get data and there is more than one co waiting for that data
  choose a random co and give him the data

- All this could be generalized to:
  - There are events
    - Type and arg
  - There are event_watchers: pairs_of: event - co
  - When an event is fired -> chech if there are watchers of this event
    - awake the associated co
    - remove events watched by the co

- Or we could have:
  - Event sources: 
    - Examples
      - Coroutines when leaving
      - Channels when data becomes available
      - Channels when data can be stored
      - Time clock
    - Members
      - List of watchers waiting for the events for each event type
  - Event watchers: The co's
    - Need to know to which event sources they are subscribed
    - Need to be able to unsubscribe from all their event sources


- If the 'watched event' is created in the stack, we don't need to malloc/free that memory
  Just be sure the events are unregistered when the thread continues
- Add a next/prev link so the events can be anywhere
- When a co wants to 'wait' for activity in two channels with a timer...
    TEventWatch events_to_watch[3] = {
      { this_handle, EVT_CHANNEL_DATA_CAN_BE_READ, channel1, &data1, next? }
    , { this_handle, EVT_CHANNEL_DATA_CAN_BE_READ, channel2, &data2, next? }
    , { this_handle, EVT_TIME, now() + 10 }
    };
    wait( events_to_watch );



- co's are dispatched by several threads, not just one (a la ps4)
- Test in unix
- Check support for coroutine local storage (or cls())


coroutines's People

Contributors

yabadabu avatar

Watchers

 avatar

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.