OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [boehm-gc/] [testsuite/] [boehm-gc.c/] [thread_leak_test.c] - Blame information for rev 721

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 721 jeremybenn
#ifndef GC_THREADS
2
# define GC_THREADS
3
#endif
4
#include "leak_detector.h"
5
#ifdef GC_PTHREADS
6
# include <pthread.h>
7
#else
8
# include <windows.h>
9
#endif
10
#include <stdio.h>
11
 
12
#ifdef GC_PTHREADS
13
  void * test(void * arg)
14
#else
15
  DWORD WINAPI test(LPVOID arg)
16
#endif
17
{
18
    int *p[10];
19
    int i;
20
    for (i = 0; i < 10; ++i) {
21
        p[i] = malloc(sizeof(int)+i);
22
    }
23
    CHECK_LEAKS();
24
    for (i = 1; i < 10; ++i) {
25
        free(p[i]);
26
    }
27
#ifdef GC_PTHREADS
28
    return arg;
29
#else
30
    return (DWORD)(GC_word)arg;
31
#endif
32
}
33
 
34
#define NTHREADS 5
35
 
36
int main(void) {
37
    int i;
38
#ifdef GC_PTHREADS
39
    pthread_t t[NTHREADS];
40
#else
41
    HANDLE t[NTHREADS];
42
    DWORD thread_id;
43
#endif
44
    int code;
45
 
46
    GC_find_leak = 1;    /* for new collect versions not compiled       */
47
    GC_INIT();
48
    for (i = 0; i < NTHREADS; ++i) {
49
#ifdef GC_PTHREADS
50
       code = pthread_create(t + i, 0, test, 0);
51
#else
52
       t[i] = CreateThread(NULL, 0, test, 0, 0, &thread_id);
53
       code = t[i] != NULL ? 0 : (int)GetLastError();
54
#endif
55
       if (code != 0) {
56
          printf("Thread creation failed %d\n", code);
57
        }
58
    }
59
    for (i = 0; i < NTHREADS; ++i) {
60
#ifdef GC_PTHREADS
61
       code = pthread_join(t[i], 0);
62
#else
63
       code = WaitForSingleObject(t[i], INFINITE) == WAIT_OBJECT_0 ? 0 :
64
                                                        (int)GetLastError();
65
#endif
66
       if (code != 0) {
67
          printf("Thread join failed %d\n", code);
68
        }
69
    }
70
    CHECK_LEAKS();
71
    CHECK_LEAKS();
72
    CHECK_LEAKS();
73
    return 0;
74
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.