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]

A bug with exceptions and threads in mainline compiler


The following  program generates a segfault after running couple tens of
seconds on linux with glibc 2.2.2 or 2.1.2 with linux threads and
compiler:

#/usr/local/bin/g++ -v
Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.0/specs
Configured with: ../gcc-20010521/configure --enable-languages=c,c++
--enable-threads
Thread model: posix
gcc version 3.0 20010521 (prerelease) 


-------------
//  compile:  /usr/local/bin/g++ -D_PTHREADS -D_REENTRANT -o xx xx.cc
-lpthreads
#include <iostream.h>
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
 
#define N_THREADS 10
 
void *x (void *arg) {
  while (1) {
    try {
      throw int ();
    }
    catch (int) { }
  }
}
 
 
pthread_t __t[N_THREADS];
 
int
main (int argc, char **argv)
{
 
 
  pthread_attr_t t_attr;
  pthread_attr_init (&t_attr);
  pthread_attr_setdetachstate (&t_attr, PTHREAD_CREATE_DETACHED);
 
  for (int i = 0; i < N_THREADS; i++)
     pthread_create (&__t[i], &t_attr, x, NULL);
 
  int uptime = 0;
  while (1) {
     sleep (1);
     uptime++;
     cout << "uptime: " << uptime << "secs\r" << flush;
  }
}  
------------------
        

-- 
/ig


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