• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 // Copyright (C) 2011 Vicente J. Botet Escriba
10 //
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)
13 
14 // <boost/thread/condition_variable.hpp>
15 
16 // void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk);
17 
18 #define BOOST_THREAD_USES_MOVE
19 #define BOOST_THREAD_VESRION 3
20 
21 #include <boost/thread/condition_variable.hpp>
22 #include <boost/thread/mutex.hpp>
23 #include <boost/thread/locks.hpp>
24 #include <boost/thread/thread.hpp>
25 #include <boost/chrono/chrono.hpp>
26 #include <boost/detail/lightweight_test.hpp>
27 
28 boost::condition_variable cv;
29 boost::mutex mut;
30 
31 typedef boost::chrono::milliseconds ms;
32 typedef boost::chrono::high_resolution_clock Clock;
33 
func()34 void func()
35 {
36   boost::unique_lock < boost::mutex > lk(mut);
37   boost::notify_all_at_thread_exit(cv, boost::move(lk));
38   boost::this_thread::sleep_for(ms(300));
39 }
40 
main()41 int main()
42 {
43   boost::unique_lock < boost::mutex > lk(mut);
44   boost::thread(func).detach();
45   Clock::time_point t0 = Clock::now();
46   cv.wait(lk);
47   Clock::time_point t1 = Clock::now();
48   BOOST_TEST(t1 - t0 > ms(250));
49   return boost::report_errors();
50 }
51 
52