diff options
author | Dan Albert <danalbert@google.com> | 2016-02-24 13:48:45 -0800 |
---|---|---|
committer | Dan Albert <danalbert@google.com> | 2016-02-24 13:51:18 -0800 |
commit | b9de1157289455b0ca26daff519d4a0ddcd1fa13 (patch) | |
tree | 4c56cc0a34b91f17033a40a455f26652304f7b8d /gcc-4.8.3/boehm-gc/testsuite/boehm-gc.c/thread_leak_test.c | |
parent | 098157a754787181cfa10e71325832448ddcea98 (diff) | |
download | toolchain_gcc-b9de1157289455b0ca26daff519d4a0ddcd1fa13.tar.gz toolchain_gcc-b9de1157289455b0ca26daff519d4a0ddcd1fa13.tar.bz2 toolchain_gcc-b9de1157289455b0ca26daff519d4a0ddcd1fa13.zip |
Update 4.8.1 to 4.8.3.
My previous drop was the wrong version. The platform mingw is
currently using 4.8.3, not 4.8.1 (not sure how I got that wrong).
From ftp://ftp.gnu.org/gnu/gcc/gcc-4.8.3/gcc-4.8.3.tar.bz2.
Bug: http://b/26523949
Change-Id: Id85f1bdcbbaf78c7d0b5a69e74c798a08f341c35
Diffstat (limited to 'gcc-4.8.3/boehm-gc/testsuite/boehm-gc.c/thread_leak_test.c')
-rw-r--r-- | gcc-4.8.3/boehm-gc/testsuite/boehm-gc.c/thread_leak_test.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/gcc-4.8.3/boehm-gc/testsuite/boehm-gc.c/thread_leak_test.c b/gcc-4.8.3/boehm-gc/testsuite/boehm-gc.c/thread_leak_test.c new file mode 100644 index 000000000..890146512 --- /dev/null +++ b/gcc-4.8.3/boehm-gc/testsuite/boehm-gc.c/thread_leak_test.c @@ -0,0 +1,74 @@ +#ifndef GC_THREADS +# define GC_THREADS +#endif +#include "leak_detector.h" +#ifdef GC_PTHREADS +# include <pthread.h> +#else +# include <windows.h> +#endif +#include <stdio.h> + +#ifdef GC_PTHREADS + void * test(void * arg) +#else + DWORD WINAPI test(LPVOID arg) +#endif +{ + int *p[10]; + int i; + for (i = 0; i < 10; ++i) { + p[i] = malloc(sizeof(int)+i); + } + CHECK_LEAKS(); + for (i = 1; i < 10; ++i) { + free(p[i]); + } +#ifdef GC_PTHREADS + return arg; +#else + return (DWORD)(GC_word)arg; +#endif +} + +#define NTHREADS 5 + +int main(void) { + int i; +#ifdef GC_PTHREADS + pthread_t t[NTHREADS]; +#else + HANDLE t[NTHREADS]; + DWORD thread_id; +#endif + int code; + + GC_find_leak = 1; /* for new collect versions not compiled */ + GC_INIT(); + for (i = 0; i < NTHREADS; ++i) { +#ifdef GC_PTHREADS + code = pthread_create(t + i, 0, test, 0); +#else + t[i] = CreateThread(NULL, 0, test, 0, 0, &thread_id); + code = t[i] != NULL ? 0 : (int)GetLastError(); +#endif + if (code != 0) { + printf("Thread creation failed %d\n", code); + } + } + for (i = 0; i < NTHREADS; ++i) { +#ifdef GC_PTHREADS + code = pthread_join(t[i], 0); +#else + code = WaitForSingleObject(t[i], INFINITE) == WAIT_OBJECT_0 ? 0 : + (int)GetLastError(); +#endif + if (code != 0) { + printf("Thread join failed %d\n", code); + } + } + CHECK_LEAKS(); + CHECK_LEAKS(); + CHECK_LEAKS(); + return 0; +} |