Opened 5 years ago

#13349 new Bugs

sregex not thread-safe when copied

Reported by: wave@… Owned by: Eric Niebler
Milestone: To Be Determined Component: xpressive
Version: Boost 1.64.0 Severity: Problem
Keywords: Cc:

Description

The following code does fail about every other execution:

#include <iostream>
#include <boost/xpressive/xpressive.hpp>
#include <boost/thread.hpp>
using namespace std;
using namespace boost::xpressive;

struct MyRegexContainer {
    boost::xpressive::sregex myPatterns[20];

    MyRegexContainer() {

        myPatterns[0] = sregex::compile("[-]?[0-9]+\\.[0-9]{2}");
        for (int i =0; i < 20; i++)
        {
                myPatterns[i] = myPatterns[0];
        }
        }

        void match(const std::string& wert, int index) const {
                        if(!regex_match(wert, myPatterns[index])){
                                cout << "Index " << index << " did not match value " << wert << endl;
                        }
        }
};


namespace {
    void testSREGEXMultithreadedTASK() {
        static const MyRegexContainer a;
        for (int i = 0; i < 10000; ++i) {
                        a.match("33.00", i%20);
                        a.match("1.11", i%20);
        }
    }
}

int main() {
#ifdef BOOST_DISABLE_THREADS
        cout << "BOOST_DISABLE_THREADS == TRUE" << wert << endl;
#endif

boost::thread_group tgroup;
    for (int i = 0; i < 100; ++i) {
        tgroup.create_thread(boost::bind(&testSREGEXMultithreadedTASK));
    }
    tgroup.join_all();

return 0;
}

Change History (0)

Note: See TracTickets for help on using tickets.