Boost logo

Boost Users :

From: John Maddock (john_at_[hidden])
Date: 2006-06-18 21:21:15


Ashish Varman wrote:
> Hello all
>
> I am getting segmentation faults when we use our program in
> multithreaded mode on linux (RedHat 9). The same code runs flawlessly
> on windows. The crash always happens in boost::regex_replace. I had
> read the following posts on this topic:
> http://lists.boost.org/MailArchives/boost/msg59110.php
> and
> http://lists.boost.org/boost-users/2005/01/9712.php
> Accordingly, I've initialised all the regexes before the main working
> threads starts.

> Stack trace is as follows:
> Program received signal SIGSEGV, Segmentation fault.
> [Switching to Thread 1129827392 (LWP 3124)]
> 0x4013f843 in

I notice that the line mentioned in the stack trace is:

switch(*m_position)

So segmentation fault occurs on iterator dereference. Is there any way that
your string being searched can be changed by another thread?

After that: are you linking against the thread safe regex lib (the one
with -mt in the name)?

If not the next sanity check to do is to build and run the test program
libs/regex/test/static_mutex/static_mutex_test.cpp - you will need to link
this to both Boost.Regex and Boost.Thread. It'll do a basic check to verify
that Boost.Regex's static mutex code is working correctly (it uses
PTHREAD_MUTEX_INITIALIZER). If this fails then there is an issue with
pthreads on the platform std lib combination you're using: try updating
glibc if you can.

After that try defining BOOST_REGEX_RECURSIVE in boost/regex/user.hpp: it'll
then use the same code that it does on Win32, however linux is rather less
tolerant of potential stack-overflows than Win32, which is why this isn't
the default. You'll need to rebuild everything, including Boost.Regex to
try this.

HTH, John.


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