fixing pr42337
[official-gcc.git] / boehm-gc / tests / thread_leak_test.c
blob1174705e45e9b7e81f32737b6bc757a2149126af
1 #define GC_LINUX_THREADS
2 #include "leak_detector.h"
3 #include <pthread.h>
4 #include <stdio.h>
6 void * test(void * arg) {
7 int *p[10];
8 int i;
9 GC_find_leak = 1; /* for new collect versions not compiled */
10 /* with -DFIND_LEAK. */
11 for (i = 0; i < 10; ++i) {
12 p[i] = malloc(sizeof(int)+i);
14 CHECK_LEAKS();
15 for (i = 1; i < 10; ++i) {
16 free(p[i]);
20 #define NTHREADS 5
22 main() {
23 int i;
24 pthread_t t[NTHREADS];
25 int code;
27 for (i = 0; i < NTHREADS; ++i) {
28 if ((code = pthread_create(t + i, 0, test, 0)) != 0) {
29 printf("Thread creation failed %d\n", code);
32 for (i = 0; i < NTHREADS; ++i) {
33 if ((code = pthread_join(t[i], 0)) != 0) {
34 printf("Thread join failed %lu\n", code);
37 CHECK_LEAKS();
38 CHECK_LEAKS();
39 CHECK_LEAKS();