|
Boost Users : |
From: Leon Mergen (leon_at_[hidden])
Date: 2005-01-26 10:16:25
Hello,
I am sorry if this is a stupid question, or simply inappropriatie for
this list. I am currently camping with this bug for way too long, so I
decided to ask this mailinglist.
I am currently in the process of finding out where a segfault is, and
how to fix it. Now, I am using the boost regex library to parse my
regexes, and for some reason when multiple threads use this regex
library, it seems to mess up and generate segfaults (it works perfectly
with only one thread). Since it also doesn't always occur on the same
place, and doesn't even occur /all/ the times, I have a strong feeling
this has something to do with thread safety.
On the Boost website is was able to find out that the boost regex
library should be thread safe when BOOST_HAS_THREADS is defined; I've
tested this, and this worked.
( http://www.boost.org/libs/regex/doc/thread_safety.html )
However, I also was able to find a mailinglist message that provides
some instructions on how to make certain boost regex functions
thread-safe :
( http://lists.boost.org/MailArchives/boost/msg59110.php )
Now, I am confused; is the boost regex library thread-safe or not ? The
solution provided in the mailinglist message ( move the regex_replace ()
function inside its own scope ) can't be applied here... :(
I've posted the stacktrace when the problem occurs and the source of the
code 'that matters' below. It also occurs in another function, I've
posted the other function too. I hope anyone has any experience with this,
or is able to help.
Thanks in advance!
Regards,
Leon Mergen
One stacktrace:
--- #0 std::string::compare(char const*) const (this=0x0, __s=0x40338b81 "C") at /root/gcc-3.3.2/i686-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.h:257 #1 0x4004b101 in boost::c_regex_traits<char>::update() () from /usr/local/lib/libboost_regex-gcc-1_31.so.1.31.0 #2 0x40084cd9 in boost::reg_expression<char, boost::regex_traits<char>, std::allocator<char> >::set_expression(char const*, char const*, unsigned) () from /usr/local/lib/libboost_regex-gcc-1_31.so.1.31.0 #3 0x080648aa in unsigned boost::reg_expression<char, boost::regex_traits<char>, std::allocator<char> >::set_expression<std::char_traits<char>, std::allocator<char> >>(std::basic_string<char, std::char_traits<char>, >>std::allocator<char> > const&, unsigned) (this=0x413d29cc, >>p=@0x413d2adc, f=34055) at basic_regex.hpp:110 #4 0x080647bf in reg_expression<std::char_traits<char>, std::allocator<char> > (this=0x413d29cc, p=@0x413d2adc, f=33031, a=@0x413d29bc) at basic_regex.hpp:114 #5 0x0806474c in basic_regex<std::char_traits<char>, std::allocator<char> > (this=0x413d29cc, p=@0x413d2adc, f=33031, a=@0x413d29bc) at basic_regex.hpp:361 #6 0x080633ee in RegexEngine::parseReplaceRegex(std::string*, std::string*, std::string*) (this=0x80d1160, regex=Cannot look up value of a typedef) at RegexEngine.cc:8 #7 0x0808070a in ModuleDigitsToText::applyModule(std::string*, std::string) (this=0x80d3190, data=0x80d16e0, language= {static npos = 4294967295, _M_dataplus ={<allocator<char>> = {<No data fields>}, _M_p = 0x80d244c "en"}, static _S_empty_rep_storage = {0, 0, 77, 0}}) at ModuleDigitsToText.cc:565 #8 0x08080270 in ModuleDigitsToText::applyModule(InputData*) (this=0x80d3190, inputData=0x80d16d8) at ModuleDigitsToText.cc:527 #9 0x08062200 in ModuleParser::parse(InputData*) (this=0x80d1150, inputData=0x80d16d8) at ModuleParser.cc:105 #10 0x0805e1db in Normaliser::normalise() (this=0x80d1698) at Normaliser.cc:107 #11 0x080831f4 in Client::operator()() (this=0x80ca808) at Client.cc:44 #12 0x080542bf in boost::detail::function::void_function_obj_invoker0<Client, void>::invoke(boost::detail::function::any_pointer) (function_obj_ptr= {obj_ptr = 0x80ca808, const_obj_ptr = 0x80ca808, func_ptr = 0x80ca808, data = "\b"}) at function_template.hpp:128 #13 0x400a69f4 in boost::thread_group::join_all() () from /usr/local/lib/libboost_thread-gcc-mt-1_31.so.1.31.0 #14 0x401cff60 in pthread_start_thread () from /lib/i686/libpthread.so.0 #15 0x401d00fe in pthread_start_thread_event () from /lib/i686/libpthread.so.0 #16 0x402f7327 in clone () from /lib/i686/libc.so.6 --- And are the two functions where the segfault occurs. Line 8 of RegexEngine.cc is the "boost::regex expression(*regex);" line of the parseReplaceRegex() function. --- std::string RegexEngine::parseReplaceRegex (const std::string * regex, const std::string * replace, const std::string * subject) { // Create an expression out of the regex boost::regex expression(*regex); // Return the replaced regex { return boost::regex_replace(*subject, expression, *replace, boost::match_default | boost::format_sed); } } bool RegexEngine::parseMatchRegex (std::string * regex, std::string * subject, RegexResultSet * what) { #ifdef DEBUG std::cout << "+ RegexEngine::parseMatchRegex[long] ( " << *regex << ", " << *subject << " )" << std::endl; #endif // DEBUG // Prepare result set boost::match_results <std::string::const_iterator> results; // Create string iterators std::string::const_iterator start = subject->begin(); std::string::const_iterator end = subject->end(); // Initialise boolean to know wether a match was reached bool success = false; // Create an expression out of the regex boost::regex expression(*regex); std::vector < std::string > regexResults; // Iterate over the results while (boost::regex_search(start, end, results, expression, boost::match_default)) { regexResults.clear(); for (boost::match_results<std::string::const_iterator>::iterator i = results.begin(); i != results.end(); ++i) { regexResults.push_back(*i); } // Push back a result what->push_back(regexResults); // Set new string iterator start = results[0].second; // Mark that a match was reached success = true; } #ifdef DEBUG std::cout << "- RegexEngine::parseMatchRegex ()" << std::endl; #endif // DEBUG // Return wether a match was reached return success; } ---
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net