Back to index

plt-scheme  4.2.1
thread_leak_test.c
Go to the documentation of this file.
00001 #define GC_LINUX_THREADS
00002 #include "leak_detector.h"
00003 #include <pthread.h>
00004 #include <stdio.h>
00005 
00006 void * test(void * arg) {
00007     int *p[10];
00008     int i;
00009     GC_find_leak = 1; /* for new collect versions not compiled  */
00010     /* with -DFIND_LEAK.                                        */
00011     for (i = 0; i < 10; ++i) {
00012         p[i] = malloc(sizeof(int)+i);
00013     }
00014     CHECK_LEAKS();
00015     for (i = 1; i < 10; ++i) {
00016         free(p[i]);
00017     }
00018 }       
00019 
00020 #define NTHREADS 5
00021 
00022 main() {
00023     int i;
00024     pthread_t t[NTHREADS];
00025     int code;
00026 
00027     for (i = 0; i < NTHREADS; ++i) {
00028        if ((code = pthread_create(t + i, 0, test, 0)) != 0) {
00029            printf("Thread creation failed %d\n", code);
00030         }
00031     }
00032     for (i = 0; i < NTHREADS; ++i) {
00033        if ((code = pthread_join(t[i], 0)) != 0) {
00034             printf("Thread join failed %lu\n", code);
00035         }
00036     }
00037     CHECK_LEAKS();
00038     CHECK_LEAKS();
00039     CHECK_LEAKS();
00040 }