mirror of
https://github.com/boostorg/thread.git
synced 2026-02-03 09:42:16 +00:00
Compare commits
5 Commits
feature/pr
...
feature/is
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1de55fceda | ||
|
|
8db325363b | ||
|
|
f71e0f1645 | ||
|
|
7f36ea346f | ||
|
|
c55e0952ee |
@@ -14,6 +14,7 @@
|
||||
#include <boost/thread/detail/move.hpp>
|
||||
#include <boost/thread/thread_functors.hpp>
|
||||
#include <boost/thread/thread_only.hpp>
|
||||
#include <boost/thread/detail/thread_interruption.hpp>
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
@@ -85,6 +86,10 @@ namespace boost
|
||||
*/
|
||||
~strict_scoped_thread()
|
||||
{
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
// exceptions from a destructor call std::terminate
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
#endif
|
||||
CallableThread on_destructor;
|
||||
|
||||
on_destructor(t_);
|
||||
@@ -188,6 +193,10 @@ namespace boost
|
||||
*/
|
||||
~scoped_thread()
|
||||
{
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
// exceptions from a destructor call std::terminate
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
#endif
|
||||
CallableThread on_destructor;
|
||||
|
||||
on_destructor(t_);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <boost/thread/detail/delete.hpp>
|
||||
#include <boost/thread/detail/move.hpp>
|
||||
#include <boost/thread/thread_functors.hpp>
|
||||
#include <boost/thread/detail/thread_interruption.hpp>
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
@@ -34,6 +35,10 @@ namespace boost
|
||||
}
|
||||
~thread_guard()
|
||||
{
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
// exceptions from a destructor call std::terminate
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
#endif
|
||||
CallableThread on_destructor;
|
||||
|
||||
on_destructor(t_);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
"std": [ "proposal" ],
|
||||
"category": [
|
||||
"Concurrent", "System"
|
||||
]
|
||||
],
|
||||
"cxxstd": "03"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -368,6 +368,10 @@ rule generate_self_contained_header_tests
|
||||
[ thread-run test_10964.cpp ]
|
||||
[ thread-test test_11053.cpp ]
|
||||
[ thread-run test_11266.cpp ]
|
||||
[ thread-run test_366_1.cpp ]
|
||||
[ thread-run test_366_2.cpp ]
|
||||
[ thread-run test_366_3.cpp ]
|
||||
[ thread-run test_366_4.cpp ]
|
||||
;
|
||||
|
||||
|
||||
|
||||
37
test/test_366_1.cpp
Normal file
37
test/test_366_1.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright 2022 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include "boost/thread/thread_guard.hpp"
|
||||
#include "boost/thread.hpp"
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
|
||||
static void inner_thread_func()
|
||||
{
|
||||
boost::this_thread::sleep_for(
|
||||
boost::chrono::hours(1) );
|
||||
}
|
||||
|
||||
static void outer_thread_func()
|
||||
{
|
||||
boost::thread inner( inner_thread_func );
|
||||
boost::thread_guard<boost::interrupt_and_join_if_joinable> guard( inner );
|
||||
}
|
||||
|
||||
static void double_interrupt()
|
||||
{
|
||||
boost::thread outer( outer_thread_func );
|
||||
boost::thread_guard<boost::interrupt_and_join_if_joinable> guard( outer );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST( true ); // perform lwt initialization
|
||||
|
||||
std::cout << "Start" << std::endl;
|
||||
double_interrupt();
|
||||
std::cout << "End" << std::endl;
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
35
test/test_366_2.cpp
Normal file
35
test/test_366_2.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright 2022 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include "boost/thread/scoped_thread.hpp"
|
||||
#include "boost/thread.hpp"
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
|
||||
static void inner_thread_func()
|
||||
{
|
||||
boost::this_thread::sleep_for(
|
||||
boost::chrono::hours(1) );
|
||||
}
|
||||
|
||||
static void outer_thread_func()
|
||||
{
|
||||
boost::scoped_thread<boost::interrupt_and_join_if_joinable> inner( inner_thread_func );
|
||||
}
|
||||
|
||||
static void double_interrupt()
|
||||
{
|
||||
boost::scoped_thread<boost::interrupt_and_join_if_joinable> outer( outer_thread_func );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST( true ); // perform lwt initialization
|
||||
|
||||
std::cout << "Start" << std::endl;
|
||||
double_interrupt();
|
||||
std::cout << "End" << std::endl;
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
35
test/test_366_3.cpp
Normal file
35
test/test_366_3.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright 2022 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include "boost/thread/scoped_thread.hpp"
|
||||
#include "boost/thread.hpp"
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
|
||||
static void inner_thread_func()
|
||||
{
|
||||
boost::this_thread::sleep_for(
|
||||
boost::chrono::hours(1) );
|
||||
}
|
||||
|
||||
static void outer_thread_func()
|
||||
{
|
||||
boost::strict_scoped_thread<boost::interrupt_and_join_if_joinable> inner( inner_thread_func );
|
||||
}
|
||||
|
||||
static void double_interrupt()
|
||||
{
|
||||
boost::strict_scoped_thread<boost::interrupt_and_join_if_joinable> outer( outer_thread_func );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST( true ); // perform lwt initialization
|
||||
|
||||
std::cout << "Start" << std::endl;
|
||||
double_interrupt();
|
||||
std::cout << "End" << std::endl;
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
59
test/test_366_4.cpp
Normal file
59
test/test_366_4.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright 2022 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include "boost/thread/scoped_thread.hpp"
|
||||
#include "boost/thread.hpp"
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
|
||||
static void do_first_half()
|
||||
{
|
||||
std::cout << "Doing first half of the work\n";
|
||||
|
||||
boost::this_thread::sleep_for(
|
||||
boost::chrono::hours( 1 ) );
|
||||
|
||||
std::cout << "First half of the work complete\n";
|
||||
}
|
||||
|
||||
static void do_second_half()
|
||||
{
|
||||
std::cout << "Doing second half of the work\n";
|
||||
|
||||
boost::this_thread::sleep_for(
|
||||
boost::chrono::hours( 1 ) );
|
||||
|
||||
std::cout << "Second half of the work complete\n";
|
||||
}
|
||||
|
||||
static void outer_thread_func()
|
||||
{
|
||||
boost::scoped_thread<boost::interrupt_and_join_if_joinable> worker1( do_first_half );
|
||||
boost::scoped_thread<boost::interrupt_and_join_if_joinable> worker2( do_second_half );
|
||||
|
||||
worker1.join();
|
||||
worker2.join();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST( true ); // perform lwt initialization
|
||||
|
||||
std::cout << "Start" << std::endl;
|
||||
|
||||
{
|
||||
boost::thread outer( outer_thread_func );
|
||||
|
||||
boost::this_thread::sleep_for( boost::chrono::seconds( 1 ) );
|
||||
|
||||
std::cout << "Interrupting work\n";
|
||||
|
||||
outer.interrupt();
|
||||
outer.join();
|
||||
}
|
||||
|
||||
std::cout << "End" << std::endl;
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
Reference in New Issue
Block a user