Enable build support by adding .onedev-buildspec.yml
await Loading last commit info...
cmake
demo
dev
examples
tests
third_party
tutorial
workloads
.clang-format
.clang-tidy
.gitignore
CMakeLists.txt
README.md
README.md

Await

Concurrency for C++ 🚀 with functional flavour λ

Demo

Prologue

You don't have to be an engineer to be a racing driver, but you do have to have Mechanical SympathyJackie Stewart, 🏎️ racing driver

Mechanical Sympathy

Features

  • Orthogonal basis for concurrency: executors × fibers × futures × cancellation
  • Scalable work-stealing task scheduler (executor) – tasks::pools::fast::ThreadPool
  • Transparent stackful fibers via tasks::fibers::Pool (backed by pools::fast::ThreadPool) with automatic pooling
  • Functional futures with extensive combinator language and fluent API
  • Futures are lazy ⟹ no dynamic memory allocations and synchronization required
  • Transparent cooperative cancellation (interruption), wait-free for sequential composition / lock-free for parallel composition
  • Structured concurrency (short-circuiting) via parallel futures combinators (All, FirstOf, etc) and fibers::WaitGroup (nursery)
  • Support for task contexts, transparent context propagation
  • Deterministic systematic tests and stress-tests with fault-injection via 🧵 Twist framework

Contents

  • Executors
    • Thread Pools (pools)
      • pools::compute::ThreadPool with shared blocking queue for independent CPU-bound tasks
      • Scalable work-stealing pools::fast::ThreadPool for fibers / stackless coroutines (IO-bound tasks)
    • Strand (asynchronous mutex)
    • ManualExecutor for deterministic testing
    • Transparent fibers (fibers)
      • fibers::Pool
      • fibers::ManualExecutor
  • Futures
    • Types (types)
      • concepts SomeFuture, Future<T>, UnitFuture
      • BoxedFuture<T>
      • EagerFuture<T>
    • Constructors (make)
      • Submit / Spawn / Invoke
      • Contract + Promise<T> (eager)
      • After
      • Value
      • Just
      • Never
    • Combinators (combine)
      • Sequential composition (seq)
        • Apply – applies user λ to future value
        • Map / AndThen / OrElse – monadic mappers for monadic value type T
        • Flatten – flattens nested futures (for asynchronous mappers)
        • FlatMap = Map + Flatten
        • Via – sets executor for following mappers
        • Sched / Yield – hints for scheduler
        • With – attaches user-defined context
        • Box – erases concrete Future type
        • Start (or Force) – converts to EagerFuture, starts operation
        • Prune (or NoInline) – prevents future inlining, releases memory / resources early
        • Clone – splits future value into two copies
        • ToUnit – erases value type to Unit
        • OnComplete / OnCancel / Anyway – asynchronous alternative to defer / RAII
        • WithTimeout – attaches timeout
        • Sequence – runs two asynchronous operations in sequence
      • Parallel composition (par)
        • All
        • FirstOf
        • Quorum
        • Join
        • Interrupt
    • Terminators (run)
      • Await – synchronously unwraps Result from future
      • Unwrap – optimistically unwraps ready Result without waiting, ~ operator * for std::optional
      • Go – starts and detaches future
    • Operators (syntax)
      • pipe: Just() | Via(pool) | Apply([]{})
      • sequence: f >> g ~ Sequence(f, g) ~ Await(f) ; g
      • bang: !f ~ f | Start()
      • unwrap: *f ~ f | Unwrap()
      • go: ~f ~ f | Go()
      • or: f or g ~ FirstOf(f, g)
      • join: f and g ~ Join(f, g)
      • sum: f + g ~ All(f, g)
  • Stackful Fibers
    • Scheduling (sched)
      • Yield
      • TeleportTo + TeleportGuard
      • SleepFor
    • Synchronization (sync)
      • Mutex (lock-free)
      • OneShotEvent (lock-free)
      • WaitGroup (lock-free)
      • Semaphore
      • CondVar
      • Channel<T> + Select
  • Timers
  • Generic Await algorithm (~ co_await)
    • Await(Future)

Examples

Tutorial

Inspiration

Requirements

Supported
Architecturex86-64, ARMv8-A-64
Operating SystemLinux, MacOS
CompilerClang++ (≥ 13)

Dependencies

  • Wheels – core components, test framework
  • Sure – context switching for stackful fibers / coroutines
  • Twist – fault injection framework for concurrency
  • Carry – user context

Third-party

Build

# Clone repo
git clone https://gitlab.com/Lipovsky/await.git 
cd await
mkdir build && cd build
# Generate build files
cmake -DAWAIT_TESTS=ON -DAWAIT_EXAMPLES=ON -DCMAKE_CXX_COMPILER=/usr/bin/clang++-13 -DCMAKE_C_COMPILER=/usr/bin/clang-13 ..
# Build example
make await_example_futures
# Run example
./examples/futures/await_example_futures

CMake options

Flags

  • AWAIT_TESTS – Enable tests
  • AWAIT_EXAMPLES – Enable examples
  • AWAIT_DEVELOPER – Developer mode: tests + examples + -Werror
  • AWAIT_MIMALLOC – Use mimalloc memory allocator
Please wait...
Page is in error, reload to recover