From 77771ee209768a8c9a78cd47c135bf4c48030629 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Fri, 1 Oct 2010 08:03:51 +0000 Subject: [PATCH] Use call_once in test code to avoid race condition which may otherwise occur. [SVN r65702] --- test/regress/test.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/regress/test.hpp b/test/regress/test.hpp index 02a08ef1..e93ac5ec 100644 --- a/test/regress/test.hpp +++ b/test/regress/test.hpp @@ -36,6 +36,9 @@ #include "test_icu.hpp" #include "test_locale.hpp" +#ifdef TEST_THREADS +#include +#endif // // define test entry proc, this forwards on to the appropriate @@ -62,6 +65,16 @@ void test(const wchar_t&, const test_regex_search_tag&); void test(const wchar_t&, const test_invalid_regex_tag&); #endif +template +struct call_once_func +{ + Regex* pregex; + void operator()()const + { + return test_empty(*pregex); + } +}; + template void do_test(const charT& c, const tagT& tag) { @@ -73,12 +86,18 @@ void do_test(const charT& c, const tagT& tag) test_info::set_typename(typeid(boost::basic_regex >).name()); #endif boost::basic_regex > e1; +#ifndef TEST_THREADS static bool done_empty_test = false; if(done_empty_test == false) { test_empty(e1); done_empty_test = true; } +#else + boost::once_flag f = BOOST_ONCE_INIT; + call_once_func > > proc = { &e1 }; + boost::call_once(f, proc); +#endif if(test_locale::cpp_locale_state() == test_locale::test_with_locale) e1.imbue(test_locale::cpp_locale()); if(test_locale::cpp_locale_state() != test_locale::no_test)