Start New Discussion within our Software Development Community

Hi everybody,

I am having some problems with a multi-threaded application I am developing. I get segmentation faults in different places, always related to std::string, using g++4.3.2 on Ubuntu 8.10 server. Here is an example:

#0  0xb7e18bb6 in memcpy () from /lib/tls/i686/cmov/libc.so.6
(gdb) up
#1  0xa8eb1014 in ?? ()
(gdb) up
#2  0xb7fca1ef in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string () from /usr/lib/libstdc++.so.6

The obvious to think is that std::string is not thread safe (and I use this extensively). I couldn't find very recent threads on the web about this, but I found an advice to compile with the flag -D_GLIBCXX_DEBUG.
This flag indeed eliminates (at least apparently) the concurrency issue with the strings.
I tried the application in windows VC++ 2008 and in this platform everything works fine [EDITED]in DEBUG mode only, although I didn't specifically set the flag.[/EDITED]

I couldn't find much info on this and there are some questions I would like to have answered like:

  • What changes in concrete when we use the flag?
  • It is still a debug mode so, will it degrade the performance if compiled without -g and with -D_GLIBCXX_DEBUG?
  • Why is windows std::string thread safe and not g++?
  • Any other solutions for this issue?

Thanks in advance

Try the compiler flag.

--enable-threads

I don't use gcc regularly so I have no idea what -D_GLIBXX_DEBUG does, this might or might not solve the problem.

Thanks in advance; in advance, taken. ;)

This article has been dead for over six months. Start a new discussion instead.