From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- src/boost/libs/thread/example/future_when_all.cpp | 330 ++++++++++++++++++++++ 1 file changed, 330 insertions(+) create mode 100644 src/boost/libs/thread/example/future_when_all.cpp (limited to 'src/boost/libs/thread/example/future_when_all.cpp') diff --git a/src/boost/libs/thread/example/future_when_all.cpp b/src/boost/libs/thread/example/future_when_all.cpp new file mode 100644 index 000000000..52a40e9c0 --- /dev/null +++ b/src/boost/libs/thread/example/future_when_all.cpp @@ -0,0 +1,330 @@ +// Copyright (C) 2012-2013 Vicente Botet +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include + +#if ! defined BOOST_NO_CXX11_DECLTYPE +#define BOOST_RESULT_OF_USE_DECLTYPE +#endif + + +#define BOOST_THREAD_VERSION 4 +//#define BOOST_THREAD_USES_LOG +#define BOOST_THREAD_USES_LOG_THREAD_ID + +#include +#include +#include +#include +#include +#if defined BOOST_THREAD_PROVIDES_FUTURE_WHEN_ALL_WHEN_ANY + +#ifdef BOOST_MSVC +#pragma warning(disable: 4127) // conditional expression is constant +#endif + +int p1() +{ + BOOST_THREAD_LOG + << "P1" << BOOST_THREAD_END_LOG; + boost::this_thread::sleep_for(boost::chrono::seconds(1)); + return 123; +} +int p1b() +{ + BOOST_THREAD_LOG + << "P1b" << BOOST_THREAD_END_LOG; + boost::this_thread::sleep_for(boost::chrono::seconds(1)); + return 321; +} + +int p2(boost::future f) +{ + BOOST_THREAD_LOG + << " P2 " << BOOST_THREAD_END_LOG; + try + { + return 2 * f.get(); + } + catch (std::exception& ex) + { + BOOST_THREAD_LOG + << "ERRORRRRR " << ex.what() << "" << BOOST_THREAD_END_LOG; + BOOST_ASSERT(false); + } + catch (...) + { + BOOST_THREAD_LOG + << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG; + BOOST_ASSERT(false); + } + BOOST_THREAD_LOG + << "P2>" << BOOST_THREAD_END_LOG; + return 0; + +} +int p2s(boost::shared_future f) +{ + BOOST_THREAD_LOG + << "" << BOOST_THREAD_END_LOG; + return 0; +} + +int main() +{ + BOOST_THREAD_LOG + << " > all0 = boost::when_all(); + BOOST_THREAD_LOG + << BOOST_THREAD_END_LOG; + } + { + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + boost::future f1 = boost::async(boost::launch::async, &p1); + boost::future > > all = boost::when_all(boost::move(f1)); + boost::csbl::tuple > res = all.get(); + BOOST_THREAD_LOG + << boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG; + } +#if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD) + { + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + boost::future f1 = boost::async(boost::launch::deferred, &p1); + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + boost::future > > all = boost::when_all(boost::move(f1)); + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + boost::csbl::tuple > res = all.get(); + BOOST_THREAD_LOG + << boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG; + } +#endif + { + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + boost::future f1 = boost::make_ready_future(1); + boost::future > > all = boost::when_all(boost::move(f1)); + boost::csbl::tuple > res = all.get(); + BOOST_THREAD_LOG + << boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG; + } + { + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + boost::future f1 = boost::async(boost::launch::async, &p1); + boost::future f2 = boost::async(boost::launch::async, &p1b); + boost::future,boost::future > > all = boost::when_all(boost::move(f1), boost::move(f2)); + //(void) all.wait(); + boost::csbl::tuple,boost::future > res = all.get(); + BOOST_THREAD_LOG + << boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG; + BOOST_THREAD_LOG + << boost::csbl::get<1>(res).get() <<" " << BOOST_THREAD_END_LOG; + } + { + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + boost::future f1 = boost::async(boost::launch::async, &p1); + boost::future f2 = boost::make_ready_future(std::string("nnnnnnn"));; + boost::future, boost::future > > all = boost::when_all(boost::move(f1), boost::move(f2)); + //(void) all.wait(); + boost::csbl::tuple, boost::future > res = all.get(); + BOOST_THREAD_LOG + << boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG; + BOOST_THREAD_LOG + << boost::csbl::get<1>(res).get() <<" " << BOOST_THREAD_END_LOG; + } + { + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + boost::csbl::vector > v; + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + v.push_back(boost::async(boost::launch::async, &p1)); + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + v.push_back(boost::async(boost::launch::async, &p1b)); + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + boost::future > > all = boost::when_all(v.begin(), v.end()); + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + boost::csbl::vector > res = all.get(); + BOOST_THREAD_LOG + << res[0].get() <<" " << BOOST_THREAD_END_LOG; + BOOST_THREAD_LOG + << res[1].get() <<" " << BOOST_THREAD_END_LOG; + } + } + catch (std::exception& ex) + { + BOOST_THREAD_LOG + << "ERRORRRRR " << ex.what() << "" << BOOST_THREAD_END_LOG; + return 1; + } + catch (...) + { + BOOST_THREAD_LOG + << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG; + return 2; + } + } + { + try + { + { + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + boost::future > all0 = boost::when_any(); + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + } + { + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + boost::future f1 = boost::async(boost::launch::async, &p1); + boost::future > > all = boost::when_any(boost::move(f1)); + boost::csbl::tuple > res = all.get(); + BOOST_THREAD_LOG + << boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG; + } +#if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD) + { + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + boost::future f1 = boost::async(boost::launch::deferred, &p1); + boost::future > > all = boost::when_any(boost::move(f1)); + boost::csbl::tuple > res = all.get(); + BOOST_THREAD_LOG + << boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG; + } +#endif + { + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + boost::future f1 = boost::async(boost::launch::async, &p1); + boost::future f2 = boost::async(boost::launch::async, &p1b); + boost::future,boost::future > > all = boost::when_any(boost::move(f1), boost::move(f2)); + boost::csbl::tuple,boost::future > res = all.get(); + BOOST_THREAD_LOG + << boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG; + BOOST_THREAD_LOG + << boost::csbl::get<1>(res).get() <<" " << BOOST_THREAD_END_LOG; + } + { + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + boost::future f1 = boost::make_ready_future(1); + boost::future f2 = boost::async(boost::launch::async, &p1b); + boost::future,boost::future > > all = boost::when_any(boost::move(f1), boost::move(f2)); + boost::csbl::tuple,boost::future > res = all.get(); + BOOST_THREAD_LOG + << boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG; + BOOST_THREAD_LOG + << boost::csbl::get<1>(res).get() <<" " << BOOST_THREAD_END_LOG; + } + { + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + boost::future f1 = boost::make_ready_future(std::string("aaaa")); + boost::future f2 = boost::async(boost::launch::async, &p1b); + boost::future,boost::future > > all = boost::when_any(boost::move(f1), boost::move(f2)); + boost::csbl::tuple,boost::future > res = all.get(); + BOOST_THREAD_LOG + << boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG; + BOOST_THREAD_LOG + << boost::csbl::get<1>(res).get() <<" " << BOOST_THREAD_END_LOG; + } + { + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + boost::future f2 = boost::make_ready_future(1); + boost::future f1 = boost::async(boost::launch::async, &p1b); + boost::future,boost::future > > all = boost::when_any(boost::move(f1), boost::move(f2)); + boost::csbl::tuple,boost::future > res = all.get(); + BOOST_THREAD_LOG + << boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG; + BOOST_THREAD_LOG + << boost::csbl::get<1>(res).get() <<" " << BOOST_THREAD_END_LOG; + } +#if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD) + { + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + boost::future f1 = boost::async(boost::launch::deferred, &p1); + boost::future f2 = boost::async(boost::launch::async, &p1b); + boost::future,boost::future > > all = boost::when_any(boost::move(f1), boost::move(f2)); + boost::csbl::tuple,boost::future > res = all.get(); + BOOST_THREAD_LOG + << boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG; + BOOST_THREAD_LOG + << boost::csbl::get<1>(res).get() <<" " << BOOST_THREAD_END_LOG; + } + { + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + boost::future f1 = boost::async(boost::launch::async, &p1); + boost::future f2 = boost::async(boost::launch::deferred, &p1b); + boost::future,boost::future > > all = boost::when_any(boost::move(f1), boost::move(f2)); + boost::csbl::tuple,boost::future > res = all.get(); + BOOST_THREAD_LOG + << boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG; + BOOST_THREAD_LOG + << boost::csbl::get<1>(res).get() <<" " << BOOST_THREAD_END_LOG; + } +#endif + { + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + boost::csbl::vector > v; + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + v.push_back(boost::async(boost::launch::async, &p1)); + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + v.push_back(boost::async(boost::launch::async, &p1b)); + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + boost::future > > all = boost::when_any(v.begin(), v.end()); + BOOST_THREAD_LOG << BOOST_THREAD_END_LOG; + boost::csbl::vector > res = all.get(); + BOOST_THREAD_LOG + << res[0].get() <<" " << BOOST_THREAD_END_LOG; + BOOST_THREAD_LOG + << res[1].get() <<" " << BOOST_THREAD_END_LOG; + } + } + catch (std::exception& ex) + { + BOOST_THREAD_LOG + << "ERRORRRRR " << ex.what() << "" << BOOST_THREAD_END_LOG; + return 1; + } + catch (...) + { + BOOST_THREAD_LOG + << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG; + return 2; + } + } + BOOST_THREAD_LOG + << "MAIN>" << BOOST_THREAD_END_LOG; + return 0; +} +#else +#include +using namespace boost; + +void f( boost::csbl::vector > &//vec + , BOOST_THREAD_RV_REF(future) //f + ) { +} +int main() +{ + boost::csbl::vector > vec; + f(vec, make_ready_future(0)); + return 0; +} +#endif -- cgit v1.2.3