Git Product home page Git Product logo

weave's Introduction

Weave

Concurrency for C++

Acknowledgements

This library was created based on my solutions for problems from the MIPT concurrency course. Major part of tests comes from the same course.

Original design (including this readme): await by Roman Lipovsky.

Features

  • Scalable work-stealing scheduler – executors::tp::fast::ThreadPool
  • Transparent stackful fibers via executors::fibers::ThreadPool with automatic pooling
  • Functional futures with almost everything deduced in compile-time
  • Futures are lazy ⟹ allocation and synchronization is minimized (usually to zero)
  • Transparent cooperative cancellation, wait-free for sequential composition and lock-free for parallel composition
  • Structured concurrency via parallel combinators ('All', 'First', etc)
  • Deterministic stress-tests with fault-injection via Twist framework

Contents

  • Executors
    • Thread Pools (ThreadPool)
      • tp::compute::ThreadPool with shared blocking queue for independent CPU-bound tasks
      • Scalable work-stealing tp::fast::ThreadPool for fibers / stackless coroutines (IO-bound tasks)
    • Strand (asynchronous mutex)
    • ManualExecutor for deterministic testing
    • Transparent fibers (fibers)
      • fibers::ThreadPool
      • fibers::ManualExecutor
  • Futures
    • Types (types)
      • concepts SomeFuture, Future<T>, EagerFuture
      • BoxedFuture<T>
    • Constructors (make)
      • After
      • Contract + Promise<T>
      • Failure
      • Just
      • Never
      • Submit
      • Value
    • Combinators (combine)
      • Sequential composition (seq)
        • Map / AndThen / OrElse – monadic mappers for Result<T>
        • Flatten – flattens nested futures (for asynchronous mappers)
        • FlatMap = Map + Flatten
        • Via – sets executor and/or hint for following mappers
        • Box – erases concrete Future (Thunk) type
        • Start (or Force) – converts to EagerFuture, starts operation
        • Fork<N> – splits future value into N copies
        • OnComplete / OnCancel / Anyway – add side effect
        • WithTimeout – attaches timeout
      • Parallel composition (par)
        • All/Both
        • First
        • Select (std::variant alternative to First which records first finished future (even if there was an error))
        • Quorum (blocking)
        • no_alloc versions which saves up allocations at the cost of less intuitive semantics
    • Terminators (run)
      • Await – synchronously unwraps Result from future
      • Detach – moves future on the stack and starts it without cancelling it
      • Discard – moves future on the stack, starts it and cancels it
    • Operators (syntax)
      • pipe: Just() | Via(pool) | Apply([]{})
      • bang: !f ~ f | Start()
      • or: f or g ~ FirstOf(f, g)
      • sum: f + g ~ All(f, g)
  • Stackful Fibers
    • Scheduling (sched)
      • Yield
      • SleepFor
    • Synchronization (sync)
      • Mutex (lock-free)
      • OneShotEvent (lock-free)
      • WaitGroup (lock-free)
      • Buffered Channel<T> + Select
      • Lock-free unbuffered experimental::Channel<T>
  • Timers

Examples

Docs

Requirements

Supported
Architecture x86-64
Operating System Linux
Compiler Clang++ (≥ 14)

Dependencies

  • Wheels – core components, test framework
  • Sure – context switching for stackful fibers / coroutines
  • Twist – fault injection framework for concurrency
  • expected - error handling
  • Mimalloc – memory allocation
  • function2 – drop-in replacement for std::function
  • fmt – formatted output

weave's People

Contributors

e1pp 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.