diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/gctest.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/gctest.c b/tests/gctest.c index ff7cd066..bf9da87a 100644 --- a/tests/gctest.c +++ b/tests/gctest.c @@ -461,10 +461,48 @@ sexpr reverse(sexpr x) return reverse1(x, nil); } +#ifdef GC_PTHREADS + /* TODO: Implement for Win32 */ + + void *do_gcollect(void *arg) + { + if (print_stats) + GC_log_printf("Collect from a standalone thread\n"); + GC_gcollect(); + return arg; + } + + void collect_from_other_thread(void) + { + pthread_t t; + int code = pthread_create(&t, NULL, do_gcollect, NULL /* arg */); + + if (code != 0) { + GC_printf("gcollect thread creation failed, errno= %d\n", code); + FAIL; + } + code = pthread_join(t, NULL); + if (code != 0) { + GC_printf("gcollect thread join failed, errno= %d\n", code); + FAIL; + } + } + +# define MAX_GCOLLECT_THREADS ((NTHREADS+2)/3) + volatile AO_t gcollect_threads_cnt = 0; +#endif /* GC_PTHREADS */ + sexpr ints(int low, int up) { if (up < 0 ? low > -up : low > up) { if (up < 0) { +# ifdef GC_PTHREADS + if (AO_fetch_and_add1(&gcollect_threads_cnt) + 1 + <= MAX_GCOLLECT_THREADS) { + collect_from_other_thread(); + return nil; + } +# endif GC_gcollect_and_unmap(); } return nil; |