]> gcc.gnu.org Git - gcc.git/blob - boehm-gc/tests/thread_leak_test.c
configure.in (GCINCS): Don't use "boehm-cflags".
[gcc.git] / boehm-gc / tests / thread_leak_test.c
1 #define GC_LINUX_THREADS
2 #include "leak_detector.h"
3 #include <pthread.h>
4 #include <stdio.h>
5
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);
13 }
14 CHECK_LEAKS();
15 for (i = 1; i < 10; ++i) {
16 free(p[i]);
17 }
18 }
19
20 #define NTHREADS 5
21
22 main() {
23 int i;
24 pthread_t t[NTHREADS];
25 int code;
26
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);
30 }
31 }
32 for (i = 0; i < NTHREADS; ++i) {
33 if ((code = pthread_join(t[i], 0)) != 0) {
34 printf("Thread join failed %lu\n", code);
35 }
36 }
37 CHECK_LEAKS();
38 CHECK_LEAKS();
39 CHECK_LEAKS();
40 }
This page took 0.04013 seconds and 5 git commands to generate.