test_11256.cpp 972 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (C) 2015 Vicente Botet
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #define BOOST_THREAD_VERSION 4
  6. #define BOOST_THREAD_PROVIDES_EXECUTORS
  7. #include <boost/thread.hpp>
  8. #include <boost/thread/thread_pool.hpp>
  9. #include <cassert>
  10. auto createFuture()
  11. {
  12. boost::promise<void> promise;
  13. promise.set_value();
  14. return promise.get_future();
  15. }
  16. auto stepOne(boost::basic_thread_pool &executor)
  17. {
  18. auto sendFuture = createFuture();
  19. auto wrappedFuture = sendFuture.then(executor, [](auto f) mutable {
  20. return createFuture();
  21. });
  22. return wrappedFuture.unwrap();
  23. }
  24. auto stepTwo(boost::basic_thread_pool &executor)
  25. {
  26. auto future = stepOne(executor);
  27. return future.then(executor, [](auto f) {
  28. assert(f.is_ready());
  29. });
  30. }
  31. int main()
  32. {
  33. boost::basic_thread_pool executor{1};
  34. stepTwo(executor).get();
  35. }