/Src/Dependencies/Boost/libs/phoenix/test/scope/bug_000008.cpp

http://hadesmem.googlecode.com/ · C++ · 97 lines · 67 code · 16 blank · 14 comment · 7 complexity · 50a3ca0281e21137c59e08256eba4d2e MD5 · raw file

  1. /*=============================================================================
  2. Copyright (c) 2003 Martin Wille
  3. Copyright (c) 2001-2007 Joel de Guzman
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. =============================================================================*/
  7. // see http://article.gmane.org/gmane.comp.parsers.spirit.general/4575
  8. // or https://sf.net/mailarchive/forum.php?thread_id=2692308&forum_id=1595
  9. // for a description of the bug being tested for by this program
  10. //
  11. // This code is borrowed from Spirit's bug_000008.cpp test for multithreads.
  12. #include <iostream>
  13. #include <boost/config.hpp>
  14. #include <boost/assert.hpp>
  15. #include <boost/detail/lightweight_test.hpp>
  16. #include <boost/spirit/home/phoenix/scope/dynamic.hpp>
  17. #if defined(DONT_HAVE_BOOST) \
  18. || !defined(BOOST_HAS_THREADS) \
  19. || defined(BOOST_DISABLE_THREADS) \
  20. || (defined(__GNUC__) && defined(__WIN32__)) // MinGW
  21. #define SKIP_TEST
  22. #endif
  23. #if defined(SKIP_TEST)
  24. // we end here if we can't do multithreading
  25. static void skipped()
  26. {
  27. std::cout << "skipped\n";
  28. }
  29. int
  30. main()
  31. {
  32. skipped();
  33. return boost::report_errors();
  34. }
  35. #else
  36. // the real MT stuff
  37. #include <boost/spirit/include/phoenix_operator.hpp>
  38. #include <boost/spirit/include/phoenix_scope.hpp>
  39. #include <boost/thread.hpp>
  40. static const int number_of_calls_per_thread=20000;
  41. struct test_dynamic : boost::phoenix::dynamic<int>
  42. {
  43. test_dynamic() : b(*this) {}
  44. member1 b;
  45. };
  46. void
  47. in_thread(void)
  48. {
  49. test_dynamic s; // should now be a local
  50. for (int i = 0; i < number_of_calls_per_thread; ++i)
  51. {
  52. boost::phoenix::dynamic_frame<test_dynamic::self_type> frame(s);
  53. (s.b = 123)();
  54. {
  55. boost::phoenix::dynamic_frame<test_dynamic::self_type> frame(s);
  56. (s.b = 456)();
  57. BOOST_ASSERT((s.b == 456)());
  58. }
  59. BOOST_ASSERT((s.b == 123)());
  60. }
  61. }
  62. void
  63. bug_000008()
  64. {
  65. boost::thread t1(in_thread);
  66. boost::thread t2(in_thread);
  67. boost::thread t3(in_thread);
  68. boost::thread t4(in_thread);
  69. t1.join();
  70. t2.join();
  71. t3.join();
  72. t4.join();
  73. }
  74. int
  75. main()
  76. {
  77. bug_000008();
  78. return boost::report_errors();
  79. }
  80. #endif