Giter Club home page Giter Club logo

cpp-futures-promises's People

Contributors

tdauth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cpp-futures-promises's Issues

Add UniqueFuture and UniquePromise

The default should be shared futures and promises.
For performance optimization, we could also provide futures and promises which can only be moved.
How do we implement derived features for such futures and promises?

Add methods share to allow a conversion.

Fix BrokenPromise support

Deleting the final promise reference to a core instance should try to complete it with BrokenPromise. This prevents starvations of programs and firstSucc automatically.

Split project

Add a separate project for comparisons with Boost and Folly.
This project should only contain the Advanced Futures and Promises.
We can drop the dependency to Folly after the splitting.

Provide an abstract class for executors which does not depend on Folly.

Fix data race bug in firstN and firstNSucc

There is a data race bug in the firstN and firstNSucc implementations. Make sure that the vector element is added BEFORE the promise is completed. Therefore, do not check if c == n but if the vector's size == n!

According to http://www.cplusplus.com/reference/vector/vector/size/ accessing the vector's size is thread-safe and does not lead to data races.
However, to be absolutely sure that the size has the correct value, we can still use the atomic size counter which is increased, after the element is added.

Add factory support

We need a factory which creates a new Core instance based on the type of a previous instance.
This allows support for different types.

The type is important for the constructor of the type adv::Promise.

At the moment the methodCore<T>::createShared(folly::Executor *executor); creates the instances.

Finish the Boost.Thread implementation

  • Test all combinators like the Folly ones in the performance tree test.
  • Complete all TODOs.
  • Add a shared future based on Boost.Thread's boost::shared_future only if it makes sense. Does it already allow registering multiple callbacks?

Memory error

There is a destructor call of a promise with an empty state in Future<T>::then<S>() when using onComplete.
Actually, there should be only one destructor call of a promise (the copy) and not two.
Where does the promise with the empty state come from?
How is it possible to create a promise with an empty state?

Memory error can be reproduced:

auto p = createPromiseInt();
p.trySuccess(10);
auto f = p.future();
auto tmp = createPromiseInt();
f.onComplete([tmp](const Try<int> &t) {});

Without capturing tmp, everything works fine.

The fix is actually very simple: Remove move constructors and assignment operators from Promise and Future. Otherwise, the shared pointer of Promise can become invalid. We do not need to move these types. They are designed to be copied.

Update to the latest stable versions of Boost, Folly and Wangle

Since September 2017, the executors of Wangle have been moved to Folly, so there is no need for Wangle anymore: https://github.com/facebook/folly/commits/ac6b1e283b5f09a39f17a2c8014275135c808bfb/folly/executors/ThreadPoolExecutor.h

Since Folly can be used as CMake package now and it is supported by CMake Hunter (https://github.com/ruslo/hunter/issues/838) maybe change to hunter to simplify the whole build process. Of course, we cannot use the latest releases/git versions of the repository then.

Do not use f.get in orElse

It blocks and if there are no threads left in the executor, it will lead to a deadlock.
Just implement it like Scala FP with transform and transformWith.

Ensure the promise life time in a tryCompleteWith call

tryCompleteWith registers a callback on the passed future with a reference to the current promise but what happens if the promise is released before the future is completed?
The destructor of the promise has to keep track of these calls and notify them.

Fix Boost.Thread unit tests for advanced futures and promises

It seems that the three test cases which fail most of the time for unique futures are:

  • unknown location(0): fatal error: in "FirstWithExceptionBoost": unknown type src/advanced/future.cpp(232): last checkpoint
  • unknown location(0): fatal error: in "TryFailureBoost": unknown type
    src/advanced/future.cpp(407): last checkpoint
  • unknown location(0): fatal error: in "TryFailureWithBoost": unknown type
    src/advanced/future.cpp(483): last checkpoint: "TryFailureWithBoost" test entry

Probably, the expected std::runtime_error is not rethrown which would be caught when catching the type std::exception. Maybe it has something to do with the storage of std::exception_ptr in the class Try.
adv_boost::Try::get() should rethrow the actual exception which has been stored under the std::exception_ptr object!
Look at folly:Try. It uses folly::exception_wrapper to store the exception.

Asked on StackOverflow: https://stackoverflow.com/questions/52043506/how-to-rethrow-the-original-exception-stored-by-an-stdexception-ptr-with-a-boo

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.