File: bug_000008.cpp

package info (click to toggle)
boost1.90 1.90.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 593,120 kB
  • sloc: cpp: 4,190,908; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,774; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (105 lines) | stat: -rw-r--r-- 2,659 bytes parent folder | download | duplicates (18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*=============================================================================
    Copyright (c) 2003 Martin Wille
    Copyright (c) 2001-2007 Joel de Guzman
    Copyright (c) 2015 John Fletcher

    Distributed under the Boost Software License, Version 1.0. (See accompanying
    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/

  // see http://article.gmane.org/gmane.comp.parsers.spirit.general/4575
  // or https://sf.net/mailarchive/forum.php?thread_id=2692308&forum_id=1595
  // for a description of the bug being tested for by this program
  //
  // This code is borrowed from Spirit's bug_000008.cpp test for multithreads.
  // Now modified to point to the Phoenix headers
  // instead of the ones in Spirit.
#include <iostream>
#include <boost/config.hpp>
#include <boost/assert.hpp>
#include <boost/detail/lightweight_test.hpp>
 // Testing problems in thread/future
//#include <boost/move/move.hpp>
//#include <boost/move/detail/type_traits.hpp>
//using boost::move_detail::is_copy_constructible;
#include <boost/phoenix/scope/dynamic.hpp>

#if defined(DONT_HAVE_BOOST)                        \
    || !defined(BOOST_HAS_THREADS)                  \
    || defined(BOOST_DISABLE_THREADS)               \
    || (defined(__GNUC__) && defined(__WIN32__))    // MinGW
#define SKIP_TEST
#endif


#if defined(SKIP_TEST)
// we end here if we can't do multithreading
static void skipped()
{
    std::cout << "skipped\n";
}

int
main()
{
    skipped();
    return boost::report_errors();
}

#else
// the real MT stuff

#include <boost/phoenix/operator.hpp>
#include <boost/phoenix/scope.hpp>
#include <boost/thread.hpp>

static const int number_of_calls_per_thread=20000;

struct test_dynamic : boost::phoenix::dynamic<int>
{
  //    test_dynamic() : b(*this) {}
  test_dynamic() : b(init<0>(this)) {}
    member1 b;
};

void
in_thread(void)
{
    test_dynamic s; // should now be a local

    for (int i = 0; i < number_of_calls_per_thread; ++i)
    {
        boost::phoenix::dynamic_frame<test_dynamic::self_type> frame(s);
        (s.b = 123)();
        {
            boost::phoenix::dynamic_frame<test_dynamic::self_type> frame(s);
            (s.b = 456)();
            BOOST_ASSERT((s.b == 456)());
        }
        BOOST_ASSERT((s.b == 123)());
    }
}

void
bug_000008()
{
    boost::thread t1(in_thread);
    boost::thread t2(in_thread);
    boost::thread t3(in_thread);
    boost::thread t4(in_thread);

    t1.join();
    t2.join();
    t3.join();
    t4.join();
}

int
main()
{
    bug_000008();
    return boost::report_errors();
}

#endif