Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65702 - trunk/libs/regex/test/regress
From: john_at_[hidden]
Date: 2010-10-01 04:03:53


Author: johnmaddock
Date: 2010-10-01 04:03:51 EDT (Fri, 01 Oct 2010)
New Revision: 65702
URL: http://svn.boost.org/trac/boost/changeset/65702

Log:
Use call_once in test code to avoid race condition which may otherwise occur.
Text files modified:
   trunk/libs/regex/test/regress/test.hpp | 19 +++++++++++++++++++
   1 files changed, 19 insertions(+), 0 deletions(-)

Modified: trunk/libs/regex/test/regress/test.hpp
==============================================================================
--- trunk/libs/regex/test/regress/test.hpp (original)
+++ trunk/libs/regex/test/regress/test.hpp 2010-10-01 04:03:51 EDT (Fri, 01 Oct 2010)
@@ -36,6 +36,9 @@
 #include "test_icu.hpp"
 #include "test_locale.hpp"
 
+#ifdef TEST_THREADS
+#include <boost/thread/once.hpp>
+#endif
 
 //
 // define test entry proc, this forwards on to the appropriate
@@ -62,6 +65,16 @@
 void test(const wchar_t&, const test_invalid_regex_tag&);
 #endif
 
+template <class Regex>
+struct call_once_func
+{
+ Regex* pregex;
+ void operator()()const
+ {
+ return test_empty(*pregex);
+ }
+};
+
 template <class charT, class tagT>
 void do_test(const charT& c, const tagT& tag)
 {
@@ -73,12 +86,18 @@
    test_info<charT>::set_typename(typeid(boost::basic_regex<charT, boost::cpp_regex_traits<charT> >).name());
 #endif
    boost::basic_regex<charT, boost::cpp_regex_traits<charT> > 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<boost::basic_regex<charT, boost::cpp_regex_traits<charT> > > 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)


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk