public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/32261]  New: Thread race segfault in std::string::append with -O and -s
@ 2007-06-08 19:32 appfault at hotmail dot com
  2007-06-08 19:50 ` [Bug c++/32261] " pinskia at gcc dot gnu dot org
                   ` (11 more replies)
  0 siblings, 12 replies; 15+ messages in thread
From: appfault at hotmail dot com @ 2007-06-08 19:32 UTC (permalink / raw)
  To: gcc-bugs

Compiling with:
g++ -g -O3 gccbug.cpp -pthread -o gccbug -s

Note that removing the -s eliminates the segfault, as does removing
optimizations with -O0.

This occurs with gcc 3.3 and 3.3.6 but does not occur with the gcc 3.2.3
delivered as part of RedHat ES3.0u5.  It is also fixed in 3.4.6.

#include <pthread.h>
#include <string>

void* thread_function(void*) {
    for (int k = 0; k < 50000; k++) {
        std::string my_str;
        my_str += "foo";
    }
    return 0;
}

int main()
{
    pthread_t thread1, thread2;

    pthread_create(&thread1, NULL, thread_function, NULL);
    pthread_create(&thread2, NULL, thread_function, NULL);

    void* exitcode;
    pthread_join(thread1, &exitcode);
    pthread_join(thread2, &exitcode);

    return 0;
}

Example stack trace (as a courtesy to future googlers looking for this issue):
#0  0x00d3d4cc in memcpy () from /lib/libc.so.6
#1  0x00ba9120 in std::string::_Rep::_M_clone (this=0x804a700,
__alloc=@0x2012783, __res=28) at
/build_gnu_build/gcc-3.3.6/i386-redhat-linux/libstdc++-v3/include/bits/char_traits.h:155
#2  0x00ba7519 in std::string::reserve (this=0xb6bf43b0, __res=28) at
/build_gnu_build/gcc-3.3.6/i386-redhat-linux/libstdc++-v3/include/bits/basic_string.h:257
#3  0x00ba77be in std::string::append (this=0xb6bf43b0, __str=@0xb6bf43a0) at
/build_gnu_build/gcc-3.3.6/i386-redhat-linux/libstdc++-v3/include/bits/basic_string.tcc:680
#4  0x08048c21 in ?? ()
#5  0x080490da in ?? ()
#6  0x08049093 in ?? ()
#7  0x08048fa6 in ?? ()
#8  0x003ef9d9 in start_thread (arg=0xb6bf4bb0) at pthread_create.c:261
#9  0x00d86f0e in clone () from /lib/libc.so.6


-- 
           Summary: Thread race segfault in std::string::append with -O and
                    -s
           Product: gcc
           Version: 3.3.6
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: appfault at hotmail dot com
  GCC host triplet: 2.4.21-32.ELsmp #1 SMP Fri Apr 15 21:17:59 EDT 2005 i686
                    i686 i3


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32261


^ permalink raw reply	[flat|nested] 15+ messages in thread
[parent not found: <bug-32261-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2015-03-24 14:56 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-08 19:32 [Bug c++/32261] New: Thread race segfault in std::string::append with -O and -s appfault at hotmail dot com
2007-06-08 19:50 ` [Bug c++/32261] " pinskia at gcc dot gnu dot org
2007-06-11 16:01 ` appfault at hotmail dot com
2007-06-12  1:36 ` jlawson-gcc at bovine dot net
2007-06-13 17:39 ` appfault at hotmail dot com
2007-06-14  1:28 ` [Bug libstdc++/32261] " pinskia at gcc dot gnu dot org
2007-06-14  2:42 ` jlawson-gcc at bovine dot net
2007-06-14  2:56   ` Andrew Pinski
2007-06-14  2:56 ` pinskia at gmail dot com
2007-06-14  8:16 ` pcarlini at suse dot de
2007-06-25 23:41 ` appfault at hotmail dot com
2007-06-25 23:50 ` pcarlini at suse dot de
2007-07-09 23:21 ` appfault at hotmail dot com
2007-09-24 17:48 ` appfault at hotmail dot com
     [not found] <bug-32261-4@http.gcc.gnu.org/bugzilla/>
2015-03-24 15:17 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).