1 /*=============================================================================
2 Copyright (c) 2003 Martin Wille
3 http://spirit.sourceforge.net/
5 Use, modification and distribution is subject to the Boost Software
6 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
10 // see http://article.gmane.org/gmane.comp.parsers.spirit.general/4575
11 // or https://sf.net/mailarchive/forum.php?thread_id=2692308&forum_id=1595
12 // for a description of the bug being tested for by this program
14 // the problem should be solved with version 1.3 of phoenix/closures.hpp>
16 #if defined(BOOST_SPIRIT_DEBUG) && defined(__GNUC__) && defined(__WIN32__)
17 // It seems that MinGW has some problems with threads and iostream ?
18 // This code crashes MinGW when BOOST_SPIRIT_DEBUG is defined. The reason
19 // is beyond me. Disable BOOST_SPIRIT_DEBUG for now.
20 #undef BOOST_SPIRIT_DEBUG
24 #include <boost/config.hpp>
25 #include <boost/core/lightweight_test.hpp>
27 #if defined(DONT_HAVE_BOOST) || !defined(BOOST_HAS_THREADS) || defined(BOOST_DISABLE_THREADS)
28 // we end here if we can't do multithreading
31 std::cout
<< "skipped\n";
38 return boost::report_errors();
44 #undef BOOST_SPIRIT_THREADSAFE
45 #define BOOST_SPIRIT_THREADSAFE
46 #undef PHOENIX_THREADSAFE
47 #define PHOENIX_THREADSAFE
49 #include <boost/spirit/include/classic_core.hpp>
50 #include <boost/spirit/include/classic_closure.hpp>
51 #include <boost/thread.hpp>
53 static const int number_of_calls_to_parse_per_thread
=20000;
56 : BOOST_SPIRIT_CLASSIC_NS::closure
<test_closure
, char const*>
62 : BOOST_SPIRIT_CLASSIC_NS::grammar
<test_grammar
, test_closure::context_t
>
66 template <typename ScannerT
>
69 definition(test_grammar
const &self
)
71 using namespace phoenix
;
72 rule
= BOOST_SPIRIT_CLASSIC_NS::epsilon_p
[self
.b
= arg1
];
75 BOOST_SPIRIT_CLASSIC_NS::rule
<ScannerT
> const &start() const { return rule
; }
77 BOOST_SPIRIT_CLASSIC_NS::rule
<ScannerT
> rule
;
86 char const text
[]="foo";
87 for(int i
=0; i
<number_of_calls_to_parse_per_thread
; ++i
)
89 BOOST_SPIRIT_CLASSIC_NS::parse(&text
[0], text
+sizeof(text
), g
);
96 boost::thread
t1(in_thread
);
97 boost::thread
t2(in_thread
);
98 boost::thread
t3(in_thread
);
99 boost::thread
t4(in_thread
);
111 return boost::report_errors();