dtor_pass.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. // <boost/thread/condition_variable>
  14. // class condition_variable;
  15. // condition_variable(const condition_variable&) = delete;
  16. #include <boost/thread/condition_variable.hpp>
  17. #include <boost/thread/mutex.hpp>
  18. #include <boost/thread/thread.hpp>
  19. #include <boost/thread/locks.hpp>
  20. #include <boost/detail/lightweight_test.hpp>
  21. boost::condition_variable* cv;
  22. boost::mutex m;
  23. typedef boost::unique_lock<boost::mutex> Lock;
  24. bool f_ready = false;
  25. bool g_ready = false;
  26. void f()
  27. {
  28. Lock lk(m);
  29. f_ready = true;
  30. cv->notify_one();
  31. cv->wait(lk);
  32. delete cv;
  33. }
  34. void g()
  35. {
  36. Lock lk(m);
  37. g_ready = true;
  38. cv->notify_one();
  39. while (!f_ready)
  40. {
  41. cv->wait(lk);
  42. }
  43. cv->notify_one();
  44. }
  45. int main()
  46. {
  47. cv = new boost::condition_variable;
  48. boost::thread th2(g);
  49. Lock lk(m);
  50. while (!g_ready)
  51. {
  52. cv->wait(lk);
  53. }
  54. lk.unlock();
  55. boost::thread th1(f);
  56. th1.join();
  57. th2.join();
  58. return boost::report_errors();
  59. }