This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]