1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
9 // Copyright (C) 2011 Vicente J. Botet Escriba
11 // Distributed under the Boost Software License, Version 1.0. (See accompanying
12 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
14 // <boost/thread/thread.hpp>
18 // template <class Rep, class Period>
19 // bool try_join_for(const chrono::duration<Rep, Period>& rel_time);
21 #define BOOST_THREAD_VESRION 3
22 #include <boost/thread/thread_only.hpp>
23 #include <boost/thread/mutex.hpp>
24 #include <boost/thread/locks.hpp>
29 #include <boost/detail/lightweight_test.hpp>
31 #if defined BOOST_THREAD_USES_CHRONO
54 BOOST_TEST(alive_
== 1);
59 bool G::op_run
= false;
61 boost::thread
* resource_deadlock_would_occur_th
=0;
62 boost::mutex resource_deadlock_would_occur_mtx
;
63 void resource_deadlock_would_occur_tester()
67 boost::unique_lock
<boost::mutex
> lk(resource_deadlock_would_occur_mtx
);
68 resource_deadlock_would_occur_th
->try_join_for(boost::chrono::milliseconds(50));
71 catch (boost::system::system_error
& e
)
73 BOOST_TEST(e
.code().value() == boost::system::errc::resource_deadlock_would_occur
);
77 BOOST_TEST(false&&"exception thrown");
83 boost::this_thread::sleep_for(boost::chrono::milliseconds(250));
89 boost::thread
t0( (G()));
90 BOOST_TEST(t0
.joinable());
91 BOOST_TEST(t0
.try_join_for(boost::chrono::milliseconds(250)));
92 BOOST_TEST(!t0
.joinable());
95 boost::thread
t0( (th_250_ms
));
96 BOOST_TEST(!t0
.try_join_for(boost::chrono::milliseconds(50)));
101 boost::unique_lock
<boost::mutex
> lk(resource_deadlock_would_occur_mtx
);
102 boost::thread
t0( resource_deadlock_would_occur_tester
);
103 resource_deadlock_would_occur_th
= &t0
;
104 BOOST_TEST(t0
.joinable());
106 boost::this_thread::sleep_for(boost::chrono::milliseconds(250));
107 boost::unique_lock
<boost::mutex
> lk2(resource_deadlock_would_occur_mtx
);
109 BOOST_TEST(!t0
.joinable());
113 boost::thread
t0( (G()));
117 t0
.try_join_for(boost::chrono::milliseconds(50));
120 catch (boost::system::system_error
& e
)
122 BOOST_TEST(e
.code().value() == boost::system::errc::invalid_argument
);
126 boost::thread
t0( (G()));
127 BOOST_TEST(t0
.joinable());
131 t0
.try_join_for(boost::chrono::milliseconds(50));
134 catch (boost::system::system_error
& e
)
136 BOOST_TEST(e
.code().value() == boost::system::errc::invalid_argument
);
141 boost::thread
t0( (G()));
142 BOOST_TEST(t0
.joinable());
143 t0
.try_join_for(boost::chrono::milliseconds(250));
149 catch (boost::system::system_error
& e
)
151 BOOST_TEST(e
.code().value() == boost::system::errc::invalid_argument
);
156 return boost::report_errors();
160 #error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"