libstdc++/5444: in multi-processor environment basic_string ist not thread safe

Reichelt reichelt@igpm.rwth-aachen.de
Tue Jan 22 08:36:00 GMT 2002


The following reply was made to PR libstdc++/5444; it has been noted by GNATS.

From: Reichelt <reichelt@igpm.rwth-aachen.de>
To: gcc-gnats@gcc.gnu.org, ljrittle@gcc.gnu.org, markus.breuer@materna.de,
        gcc-bugs@gcc.gnu.org
Cc:  
Subject: Re: libstdc++/5444: in multi-processor environment basic_string ist not thread safe
Date: Tue, 22 Jan 2002 17:49:10 +0100

 Hi,
 
 I can confirm the problems with the example in PR5444.
 I compiled the program with gcc 3.1-20020121 (configured with
 "--enable-threads") on a dual i686-pc-linux-gnu box.
 Running it I get segfaults most of the time, but no memory growth.
 I only need to run one instance to get the segfault.
 
 I tried to reduce the exapmle a little bit and to get rid of the
 deprecated header <strstream> and came up with to following example
 that crashes within less than a second most of the time
 (just compile with "g++ filename.cpp -lpthread"):
 
 #include <pthread.h>
 #include <unistd.h>
 #include <iostream>
 #include <sstream>
 
 const int max_thread_count = 8;
 volatile int runningThreads = max_thread_count;
 
 pthread_t tid[ max_thread_count ];
 
 void* thread_main (void*)
 {
    std::cout << "Entering thread ..." << std::endl;
 
    for (int i=0; i<10000; ++i )
       std::ostringstream oss;
 
    std::cout << "Leaving thread ..." << std::endl;
    runningThreads--;
 }
 
 
 int main()
 {
    std::cout << "Startup ..." << std::endl;
 
    for ( int i=0; i < max_thread_count; ++i )
    {
       pthread_create( &tid[i], 0, thread_main, 0 );
       std::cout << "thread " << i+1 << " started ..." << std::endl;
    }
 
    while ( runningThreads )
       sleep (1);
 
    std::cout << "Shutdown ..." << std::endl;
 
    return 0;
 }
 
 The problem seems to be hidden in the command "std::ostringstream oss;".
 If I replace it with some different dummy code, everything works fine.
 
 Greetings,
 Volker Reichelt
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5444
 
 



More information about the Gcc-prs mailing list