Seg faults when using boost::regex_replace in multiple threads
Hello, I'm having a few problems with boost::regex_replace seg faulting when used in a multithreaded program. The problem seems to be identical to the one described in http://lists.boost.org/boost-users/2006/06/20235.php, with a seg fault on line 133 of regex_format.hpp, though I have linked against the multithreaded version of libboost_regex.so and the problem is still happening. Unfortunately, I never saw any definitive answer for what was causing the original poster's problems. =========================================== Stack trace: =========================================== Program received signal SIGSEGV, Segmentation fault. [Switching to Thread -584664144 (LWP 28385)] 0x080520e0 in boost::re_detail::basic_regex_formatter<boost::re_detail::string_out_ite rator<std::string>, boost::match_results<char const*, std::allocator<boost::sub_match<char const*> > >, boost::regex_traits_wrapper<boost::regex_traits<char, boost::cpp_regex_traits<char> > > >::format_all (this=0xdd26b8d0) at regex_format.hpp:133 133 switch(*m_position) (gdb) where #0 0x080520e0 in boost::re_detail::basic_regex_formatter<boost::re_detail::string_out_ite rator<std::string>, boost::match_results<char const*, std::allocator<boost::sub_match<char const*> > >, boost::regex_traits_wrapper<boost::regex_traits<char, boost::cpp_regex_traits<char> > > >::format_all (this=0xdd26b8d0) at regex_format.hpp:133 #1 0x080518be in boost::re_detail::basic_regex_formatter<boost::re_detail::string_out_ite rator<std::string>, boost::match_results<char const*, std::allocator<boost::sub_match<char const*> > >, boost::regex_traits_wrapper<boost::regex_traits<char, boost::cpp_regex_traits<char> > > >::format (this=0xdd26b8d0, p1=0xd55005dc "$1", p2=0xd55005de "", f=format_all) at regex_format.hpp:123 #2 0x08051073 in boost::re_detail::regex_format_imp<boost::re_detail::string_out_iterator <std::string>, char const*, std::allocator<boost::sub_match<char const*>
, char, boost::regex_traits_wrapper<boost::regex_traits<char,
boost::cpp_regex_traits<char> > > > (out= {<std::iterator<std::output_iterator_tag, char, int, char*, char&>> = {<No data fields>}, out = 0xdd26ba70}, m=@0xd5500518, p1=0xd55005dc "$1", p2=0xd55005de "", flags=format_all, t=@0x8064140) at regex_format.hpp:569 #3 0x08050710 in format<boost::re_detail::string_out_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > > (this=0xd5500518, out={<std::iterator<std::output_iterator_tag, char, int, char*, char&>> = {<No data fields>}, out = 0xdd26ba70}, fmt=@0xdd26b990, flags=format_all, re=@0x805f6ec) at match_results.hpp:170 #4 0x0804fe35 in boost::regex_replace<boost::re_detail::string_out_iterator<std::string>, char const*, boost::regex_traits<char, boost::cpp_regex_traits<char> >, char> (out= {<std::iterator<std::output_iterator_tag, char, int, char*, char&>> = {<No data fields>}, out = 0xdd26ba70}, first=0xd550048c "abcdefgh", last=0xd5500494 "", e=@0x805f6ec, fmt=0x805a2a9 "$1", flags=format_all) at regex_replace.hpp:53 #5 0x0804f7e1 in boost::regex_replace<boost::regex_traits<char, boost::cpp_regex_traits<char> >, char> (s=@0xdd26ba80, e=@0x805f6ec, fmt=0x805a2a9 "$1", flags=format_all) at regex_replace.hpp:84 #6 0x0804f3c4 in test_fn () at regexTest.C:32 #7 0xf63e5dec in start_thread () from /lib/tls/libpthread.so.0 #8 0xf6385a2a in clone () from /lib/tls/libc.so.6 (gdb) print *this $1 = {m_traits = @0x8064140, m_results = @0xd5500518, m_out = {<std::iterator<std::output_iterator_tag, char, int, char*, char&>> = {<No data fields>}, out = 0xdd26ba70}, m_position = 0xd44ff5d6 <Address 0xd44ff5d6 out of bounds>, m_end = 0xd55005de "", m_flags = format_all, m_state = output_copy, m_have_conditional = false} ========================================== GCC version is 3.2.3 20030502 (Red Hat Linux 3.2.3-42), with Boost 1.33.1, on a 4 CPU machine. We're using the STL from RogueWave, though since the post from a couple of weeks ago had the same problem with both GCC and STLport libraries I don't think that's the problem. This problem also occurs with version 1.33.0, but not with 1.32 or earlier. Does anyone know if there is a known problem with using these new versions of boost::regex_replace in multiple threads? If it's helpful, I have a very simple test program that demonstrates the problem. Any help on this would be greatly appreciated. Kind regards, Alistair Potts
mailinglist@kamba.net.nz wrote:
Does anyone know if there is a known problem with using these new versions of boost::regex_replace in multiple threads? If it's helpful, I have a very simple test program that demonstrates the problem. Any help on this would be greatly appreciated.
If you can let me have the test program I can at least try and reproduce it. I must admit to being at a loss to explain this otherwise: there really is no thread sensitive code inside regex_replace. John.
Sure. Here's a very simple program that does nothing useful, but which crashes consistently on a multi-processor machine. Kind regards, Alistair #include <boost/regex.hpp> #include <iostream> #include <string> #include <pthread.h> const char* const reExpr("abcd(.*)"); const char* const replaceExpr("$1"); boost::regex re(reExpr); size_t noThreads(50); pthread_barrier_t barrier; extern "C" { void* test_fn(void*) { pthread_barrier_wait(&barrier); while(1) { std::string expr("abcdefgh"); std::cout << boost::regex_replace(expr, re, replaceExpr, boost::match_default|boost::format_all) << std::endl; } return 0; } } int main(int argc,char* argv[]) { pthread_t* threads = new pthread_t[noThreads]; pthread_barrier_init(&barrier, NULL, noThreads); size_t i = 0; for (; i < noThreads; ++i) { if(pthread_create(&(threads[i]), NULL, test_fn, NULL)) { std::cerr << "Error creating thread" << std::endl; return 1; } } for(i = 0; i < noThreads; ++i) pthread_join(threads[i], NULL); exit(0); } -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of John Maddock Sent: 11 July 2006 10:02 To: boost-users@lists.boost.org Subject: Re: [Boost-users] Seg faults when using boost::regex_replaceinmultiple threads mailinglist@kamba.net.nz wrote:
Does anyone know if there is a known problem with using these new versions of boost::regex_replace in multiple threads? If it's helpful, I have a very simple test program that demonstrates the problem. Any help on this would be greatly appreciated.
If you can let me have the test program I can at least try and reproduce it. I must admit to being at a loss to explain this otherwise: there really is no thread sensitive code inside regex_replace. John. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Alistair Potts
-
John Maddock
-
mailinglist@kamba.net.nz