From d584923a1e1fe92a4bb38b2cd1f0bf5a3b7802f0 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Sun, 1 Dec 2019 19:58:43 -0500 Subject: testsuite: Fix thread leak in hs_try_putmvar00[13] --- testsuite/tests/concurrent/should_run/hs_try_putmvar001_c.c | 1 + testsuite/tests/concurrent/should_run/hs_try_putmvar003_c.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/testsuite/tests/concurrent/should_run/hs_try_putmvar001_c.c b/testsuite/tests/concurrent/should_run/hs_try_putmvar001_c.c index f214c5c4d0..583c23c2c6 100644 --- a/testsuite/tests/concurrent/should_run/hs_try_putmvar001_c.c +++ b/testsuite/tests/concurrent/should_run/hs_try_putmvar001_c.c @@ -28,4 +28,5 @@ void scheduleCallback(HsStablePtr mvar, HsInt cap, int *presult) p->cap = cap; p->presult = presult; pthread_create(&t, NULL, callback, p); + pthread_detach(t); } diff --git a/testsuite/tests/concurrent/should_run/hs_try_putmvar003_c.c b/testsuite/tests/concurrent/should_run/hs_try_putmvar003_c.c index d67ca43218..d3bf142455 100644 --- a/testsuite/tests/concurrent/should_run/hs_try_putmvar003_c.c +++ b/testsuite/tests/concurrent/should_run/hs_try_putmvar003_c.c @@ -6,6 +6,7 @@ #include "hs_try_putmvar003_stub.h" struct callback_queue { + pthread_t thread; pthread_mutex_t lock; pthread_cond_t cond; int use_foreign_export; @@ -54,18 +55,18 @@ typedef void* threadfunc(void *); struct callback_queue* mkCallbackQueue(int use_foreign_export, int n_requests) { struct callback_queue *q = malloc(sizeof(struct callback_queue)); - pthread_t t; pthread_mutex_init(&q->lock, NULL); pthread_cond_init(&q->cond, NULL); q->pending = NULL; q->use_foreign_export = use_foreign_export; q->n_requests = n_requests; - pthread_create(&t, NULL, (threadfunc*)callback, q); + pthread_create(&q->thread, NULL, (threadfunc*)callback, q); return q; } void destroyCallbackQueue(struct callback_queue *q) { + pthread_join(q->thread, NULL); pthread_mutex_destroy(&q->lock); pthread_cond_destroy(&q->cond); free(q); -- cgit v1.2.1