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/test/test_thread_exit.cpp | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.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/test/test_thread_exit.cpp')
-rw-r--r-- | src/boost/libs/thread/test/test_thread_exit.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/boost/libs/thread/test/test_thread_exit.cpp b/src/boost/libs/thread/test/test_thread_exit.cpp new file mode 100644 index 000000000..577bcd05d --- /dev/null +++ b/src/boost/libs/thread/test/test_thread_exit.cpp @@ -0,0 +1,63 @@ +// (C) Copyright 2009 Anthony Williams +// +// 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/thread/thread_only.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/condition.hpp> +#include <boost/thread/future.hpp> +#include <utility> +#include <memory> +#include <string> + +#define BOOST_TEST_MODULE Boost.Threads: thread exit test suite + +#include <boost/test/unit_test.hpp> + +boost::thread::id exit_func_thread_id; + +void exit_func() +{ + exit_func_thread_id=boost::this_thread::get_id(); +} + +void tf1() +{ + boost::this_thread::at_thread_exit(exit_func); + BOOST_CHECK(exit_func_thread_id!=boost::this_thread::get_id()); +} + +BOOST_AUTO_TEST_CASE(test_thread_exit_func_runs_when_thread_exits) +{ + exit_func_thread_id=boost::thread::id(); + boost::thread t(&tf1); + boost::thread::id const t_id=t.get_id(); + t.join(); + BOOST_CHECK(exit_func_thread_id==t_id); +} + +struct fo +{ + void operator()() + { + exit_func_thread_id=boost::this_thread::get_id(); + } +}; + +void tf2() +{ + boost::this_thread::at_thread_exit(fo()); + BOOST_CHECK(exit_func_thread_id!=boost::this_thread::get_id()); +} + + +BOOST_AUTO_TEST_CASE(test_can_use_function_object_for_exit_func) +{ + exit_func_thread_id=boost::thread::id(); + boost::thread t(tf2); + boost::thread::id const t_id=t.get_id(); + t.join(); + BOOST_CHECK(exit_func_thread_id==t_id); +} |