diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/boost/libs/thread/example/serial_executor.cpp | |
parent | Initial commit. (diff) | |
download | ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.tar.xz ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/thread/example/serial_executor.cpp')
-rw-r--r-- | src/boost/libs/thread/example/serial_executor.cpp | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/src/boost/libs/thread/example/serial_executor.cpp b/src/boost/libs/thread/example/serial_executor.cpp new file mode 100644 index 000000000..e3c2c340a --- /dev/null +++ b/src/boost/libs/thread/example/serial_executor.cpp @@ -0,0 +1,107 @@ +// Copyright (C) 2015 Vicente J. Botet Escriba +// +// 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 <boost/config.hpp> +#if ! defined BOOST_NO_CXX11_DECLTYPE +#define BOOST_RESULT_OF_USE_DECLTYPE +#endif + +#define BOOST_THREAD_VERSION 4 +#define BOOST_THREAD_PROVIDES_EXECUTORS +//#define BOOST_THREAD_USES_LOG +#define BOOST_THREAD_USES_LOG_THREAD_ID +#define BOOST_THREAD_QUEUE_DEPRECATE_OLD + +#include <boost/thread/caller_context.hpp> +#include <boost/thread/executors/basic_thread_pool.hpp> +#include <boost/thread/executors/serial_executor.hpp> +#include <boost/thread/executors/executor.hpp> +#include <boost/thread/executors/executor_adaptor.hpp> +#include <boost/thread/executor.hpp> +#include <boost/thread/future.hpp> +#include <boost/assert.hpp> +#include <string> +#include <iostream> + +void p1() +{ + //std::cout << BOOST_CONTEXTOF << std::endl; + boost::this_thread::sleep_for(boost::chrono::milliseconds(30)); + //std::cout << BOOST_CONTEXTOF << std::endl; +} + +void p2() +{ + //std::cout << BOOST_CONTEXTOF << std::endl; + boost::this_thread::sleep_for(boost::chrono::milliseconds(10)); + //std::cout << BOOST_CONTEXTOF << std::endl; +} + +int f1() +{ + // std::cout << BOOST_CONTEXTOF << std::endl; + boost::this_thread::sleep_for(boost::chrono::seconds(1)); + return 1; +} +int f2(int i) +{ + // std::cout << BOOST_CONTEXTOF << std::endl; + boost::this_thread::sleep_for(boost::chrono::seconds(2)); + return i + 1; +} + +void submit_some(boost::serial_executor& tp) +{ + for (int i = 0; i < 3; ++i) { + std::cout << BOOST_CONTEXTOF << std::endl; + tp.submit(&p2); + } + for (int i = 0; i < 3; ++i) { + std::cout << BOOST_CONTEXTOF << std::endl; + tp.submit(&p1); + } + +} + + +void at_th_entry(boost::basic_thread_pool& ) +{ + +} + +int test_executor_adaptor() +{ + { + try + { + +#if ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + { + boost::basic_thread_pool ea1(4); + boost::serial_executor ea2(ea1); + submit_some(ea2); + boost::this_thread::sleep_for(boost::chrono::seconds(10)); + } +#endif + } + catch (std::exception& ex) + { + std::cout << "ERROR= " << ex.what() << "" << std::endl; + return 1; + } + catch (...) + { + std::cout << " ERROR= exception thrown" << std::endl; + return 2; + } + } + return 0; +} + + +int main() +{ + return test_executor_adaptor(); +} |