PageRenderTime 53ms CodeModel.GetById 41ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

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