This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
libstdc++/2932: new operator segfaults for arrays using pthreads on hpux
- To: gcc-gnats at gcc dot gnu dot org
- Subject: libstdc++/2932: new operator segfaults for arrays using pthreads on hpux
- From: rob dot renfrew at epiphany dot com
- Date: 24 May 2001 23:48:36 -0000
- Reply-To: rob dot renfrew at epiphany dot com
>Number: 2932
>Category: libstdc++
>Synopsis: new operator segfaults for arrays using pthreads on hpux
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu May 24 16:56:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: rob.renfrew@epiphany.com
>Release: gcc version 2.95.2 19991024 (release)
>Organization:
>Environment:
HP-UX 11
>Description:
spawning many threads which each allocate new arrays will cause a segmentation fault on HPUX11. error does not occur using new to allocate non-arrays, or with malloc().
>How-To-Repeat:
build as:
gcc -o RTT RTT.cpp -lpthread
run ./RTT
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="RTT.cpp"
Content-Disposition: inline; filename="RTT.cpp"
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#define NUM_THREADS 100
#define NUM_LOOPS 100
#define RT_SIZE 100
//typedef unsigned short Rtype;
typedef char Rtype;
void* memory_test(void *arg) {
for (int i = 0; i < NUM_LOOPS; i++) {
Rtype* rt = new Rtype[RT_SIZE];
delete rt;
}
}
int main(int argc, char **argv) {
int status;
pthread_t *threads;
threads = new pthread_t[NUM_THREADS];
for (int i = 0; i < NUM_THREADS; i++) {
status = pthread_create(&(threads[i]), NULL, memory_test, NULL);
if (status != 0) {
fprintf(stderr, "failed: pthread_create: %d\n", i);
exit(-1);
}
}
void *trash;
for (int i = 0; i < NUM_THREADS; i++) {
status = pthread_join(threads[i], &trash);
if (status != 0) {
fprintf(stderr, "failed: pthread_join: %d\n", i);
exit(-1);
}
}
return 0;
}