source: trunk/gc6.8/tests/thread_leak_test.c

Last change on this file was 132, checked in by cinc, 19 years ago

Boehm-Demers-Weiser garbage collector. Single-threaded for OS/2.

File size: 896 bytes
Line 
1#define GC_LINUX_THREADS
2#include "leak_detector.h"
3#include <pthread.h>
4#include <stdio.h>
5
6void * 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
22main() {
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}
Note: See TracBrowser for help on using the repository browser.