diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/thread/example/thread_pool.cpp | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/thread/example/thread_pool.cpp')
-rw-r--r-- | src/boost/libs/thread/example/thread_pool.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/boost/libs/thread/example/thread_pool.cpp b/src/boost/libs/thread/example/thread_pool.cpp new file mode 100644 index 00000000..bf9b64e1 --- /dev/null +++ b/src/boost/libs/thread/example/thread_pool.cpp @@ -0,0 +1,78 @@ +// 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 <boost/config.hpp> + +#define BOOST_THREAD_VERSION 5 +//#define BOOST_THREAD_USES_LOG +#define BOOST_THREAD_USES_LOG_THREAD_ID +#define BOOST_THREAD_QUEUE_DEPRECATE_OLD +#if ! defined BOOST_NO_CXX11_DECLTYPE +#define BOOST_RESULT_OF_USE_DECLTYPE +#endif + +#include <boost/thread/detail/log.hpp> +#include <boost/thread/executors/basic_thread_pool.hpp> +#include <boost/thread/thread_only.hpp> +#include <boost/assert.hpp> +#include <string> + +#ifdef BOOST_MSVC +#pragma warning(disable: 4127) // conditional expression is constant +#endif + +void p1() +{ + BOOST_THREAD_LOG + << boost::this_thread::get_id() << " P1" << BOOST_THREAD_END_LOG; +} + +void p2() +{ + BOOST_THREAD_LOG + << boost::this_thread::get_id() << " P2" << BOOST_THREAD_END_LOG; +} + +void submit_some(boost::basic_thread_pool& tp) { + tp.submit(&p1); + tp.submit(&p2); + tp.submit(&p1); + tp.submit(&p2); + tp.submit(&p1); + tp.submit(&p2); + tp.submit(&p1); + tp.submit(&p2); + tp.submit(&p1); + tp.submit(&p2); +} + + +int main() +{ + BOOST_THREAD_LOG + << boost::this_thread::get_id() << " <MAIN" << BOOST_THREAD_END_LOG; + { + try + { + boost::basic_thread_pool tp; + submit_some(tp); + } + 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 + << boost::this_thread::get_id() << "MAIN>" << BOOST_THREAD_END_LOG; + return 0; +} |