1// Copyright 2022 Peter Dimov
2// Distributed under the Boost Software License, Version 1.0.
3// https://www.boost.org/LICENSE_1_0.txt
4
5#include "boost/thread/thread_guard.hpp"
6#include "boost/thread.hpp"
7#include <boost/core/lightweight_test.hpp>
8#include <iostream>
9
10static void inner_thread_func()
11{
12 boost::this_thread::sleep_for(
13 d: boost::chrono::hours(1) );
14}
15
16static void outer_thread_func()
17{
18 boost::thread inner( inner_thread_func );
19 boost::thread_guard<boost::interrupt_and_join_if_joinable> guard( inner );
20}
21
22static void double_interrupt()
23{
24 boost::thread outer( outer_thread_func );
25 boost::thread_guard<boost::interrupt_and_join_if_joinable> guard( outer );
26}
27
28int main()
29{
30 BOOST_TEST( true ); // perform lwt initialization
31
32 std::cout << "Start" << std::endl;
33 double_interrupt();
34 std::cout << "End" << std::endl;
35
36 return boost::report_errors();
37}
38

source code of boost/libs/thread/test/test_366_1.cpp