All Projects → VestniK → Portable_concurrency

VestniK / Portable_concurrency

Licence: cc0-1.0
Portable implementation of future/promise API in C++

Programming Languages

cpp
1120 projects
cpp14
131 projects

Projects that are alternatives of or similar to Portable concurrency

YACLib
Yet Another Concurrency Library
Stars: ✭ 193 (+302.08%)
Mutual labels:  concurrency, future
Java Concurrency Examples
Java Concurrency/Multithreading Tutorial with Examples for Dummies
Stars: ✭ 173 (+260.42%)
Mutual labels:  concurrency, future
Asyncninja
A complete set of primitives for concurrency and reactive programming on Swift
Stars: ✭ 146 (+204.17%)
Mutual labels:  concurrency, future
async
Synchronization and asynchronous computation package for Go
Stars: ✭ 104 (+116.67%)
Mutual labels:  concurrency, future
Rxjava Android Samples
Learning RxJava for Android by example
Stars: ✭ 7,520 (+15566.67%)
Mutual labels:  concurrency
Java Concurrency
Checklist for code reviews
Stars: ✭ 842 (+1654.17%)
Mutual labels:  concurrency
Vngo
golang version of vn.py
Stars: ✭ 25 (-47.92%)
Mutual labels:  future
Then
🎬 Tame async code with battle-tested promises
Stars: ✭ 908 (+1791.67%)
Mutual labels:  future
Vibe.d
Official vibe.d development
Stars: ✭ 1,043 (+2072.92%)
Mutual labels:  concurrency
Three Chat Servers
Example code to go with the talk of the same name and the Ruby Magic concurrency series of blog posts.
Stars: ✭ 46 (-4.17%)
Mutual labels:  concurrency
Asyncio
asyncio historical repository
Stars: ✭ 952 (+1883.33%)
Mutual labels:  concurrency
Bloc
A predictable state management library that helps implement the BLoC design pattern
Stars: ✭ 8,214 (+17012.5%)
Mutual labels:  concurrency
Jdonframework
Domain-Driven-Design Pub/Sub Domain-Events framework
Stars: ✭ 978 (+1937.5%)
Mutual labels:  concurrency
Bree
🚥 The best job scheduler for Node.js and JavaScript with cron, dates, ms, later, and human-friendly support. Works in Node v10+ and browsers, uses workers to spawn sandboxed processes, and supports async/await, retries, throttling, concurrency, and graceful shutdown. Simple, fast, and lightweight. Made for @ForwardEmail and @ladjs.
Stars: ✭ 933 (+1843.75%)
Mutual labels:  concurrency
Phobos
The standard library of the D programming language
Stars: ✭ 1,038 (+2062.5%)
Mutual labels:  concurrency
Go Concurrency Test
Test the performance of Go's concurrency structures
Stars: ✭ 24 (-50%)
Mutual labels:  concurrency
Pykka
🌀 Pykka makes it easier to build concurrent applications.
Stars: ✭ 944 (+1866.67%)
Mutual labels:  concurrency
Zeromq Ng
⚡️ Next-generation Node.js bindings to the ZeroMQ library
Stars: ✭ 45 (-6.25%)
Mutual labels:  concurrency
Pulsar
Fibers, Channels and Actors for Clojure
Stars: ✭ 885 (+1743.75%)
Mutual labels:  concurrency
Libzmq
ZeroMQ core engine in C++, implements ZMTP/3.1
Stars: ✭ 7,418 (+15354.17%)
Mutual labels:  concurrency

portable_concurrency

Build status Build status

CC0 licensed

Code documented

std::future done right. Simple to use portable implementation of the future/promise API inspired by the C++ Extensions for Concurrency TS and some parts of A Unified Executors Proposal for C++.

  • Minimum requred C++ standard: C++14
  • The only public dependency: standard library.
  • The only build dependency: gtest

Key features

  • Execcutor aware
    pc::static_thread_pool pool{5};
    pc::future<int> answer = pc::async(pool.executor(), [] {return 42;});
    
  • Designed to work with user provided executors
    namespace portable_concurrency {
    template<> struct is_executor<QThreadPool*>: std::true_type {};
    }
    void post(QThreadPool*, pc::unique_function<void()>);
    
    pc::future<int> answer = pc::async(QThreadPool::globalInstance(), [] {return 42;});
    
  • Continuations support
    pc::static_thread_pool pool{5};
    asio::io_context io;
    pc::future<rapidjson::Document> res = pc::async(io.get_executor(), receive_document)
      .next(pool.executor(), parse_document);
    
  • when_all/when_any composition of futures
    pc::future<rapidjson::Document> res = pc::when_any(
      pc::async(pool.executor(), fetch_from_cache),
      pc::async(io.get_executor(), receive_from_network)
    ).next([](auto when_any_res) {
      switch(when_any_res.index) {
        case 0: return std::get<0>(when_any_res.futures);
        case 1: return std::get<1>(when_any_res.futures);
      }
    }); 
    
  • future<future<T>> transparently unwrapped to future<T>
  • future<shared_future<T>> transparently unwrapped to shred_future<T>
  • Automatic task cancelation:
    • Not yet started functions passed to pc::async/pc::packaged_task or attached to intermediate futures as continuations may not be executed at all if future or all shared_future's on the result of continuations chain are destroyed.
    • future::detach() and shared_future::detach() functions allows to destroy future without cancelation of any tasks.
      auto future = pc::async(pool.executor(), important_calculation)
        .next(io.get_executor(), important_io)
        .detach()
        .next(pool.executor(), not_so_important_calculations);
      
      important_calculation and important_io are guarantied to be executed even in case of premature future destruction.
    • promise::is_awaiten() allows to check if there is a future or shared_future waiting for value to be set on this promise object.
    • promise::promise(canceler_arg_t, CancelAction) constructor allows to specify action which is called in case of cancelation via future destruction.
    • Additional then overload to check if task is canceled from the continuations function
      pc::future<std::string> res = pc::async(pool.executor(), [] {return 42;})
        .then([](pc::promise<std::string> p, pc::future<int> f) {
          std::string res;
          while (has_work_to_do()) {
            do_next_step(res, f);
            if (!p.is_awaiten())
              return;
          }
          p.set_value(res);
        });
      

Build

mkdir -p build/debug
cd build/debug
conan remote add pdeps https://api.bintray.com/conan/pdeps/deps
conan install --build=missing ../..
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug ../..
ninja
ninja test
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].