~ubuntu-branches/ubuntu/natty/libgc/natty-updates

« back to all changes in this revision

Viewing changes to tests/thread_leak_test.c

  • Committer: Bazaar Package Importer
  • Author(s): Ryan Murray
  • Date: 2002-03-25 20:27:15 UTC
  • Revision ID: james.westby@ubuntu.com-20020325202715-terff7kao1wrwok5
Tags: upstream-6.0+6.1alpha4
ImportĀ upstreamĀ versionĀ 6.0+6.1alpha4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
}