From ac7fec70a065fb5967783888878f96bcc96f8e77 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Sun, 3 Jan 2016 21:59:09 -0500 Subject: [PATCH] Finalize mutex prior to sweeping --- gc.c | 9 +++++++++ test.scm | 1 + 2 files changed, 10 insertions(+) diff --git a/gc.c b/gc.c index 37de0fd2..f79a554a 100644 --- a/gc.c +++ b/gc.c @@ -573,6 +573,15 @@ size_t gc_sweep(gc_heap *h, size_t *sum_freed_ptr) fprintf(stderr, "sweep is freeing unmarked obj: %p with tag %ld\n", p, type_of(p)); #endif mark(p) = gc_color_blue; // Needed? + if (type_of(p) == mutex_tag) { +#if GC_DEBUG_VERBOSE + fprintf(stderr, "pthread_mutex_destroy from sweep\n"); +#endif + if (pthread_mutex_destroy(&(((mutex)p)->lock)) != 0) { + fprintf(stderr, "Error destroying mutex\n"); + exit(1); + } + } // free p heap_freed += size; if (((((char *)q) + q->size) == (char *)p) && (q != h->free_list)) { diff --git a/test.scm b/test.scm index 203994f1..f67c442b 100644 --- a/test.scm +++ b/test.scm @@ -14,6 +14,7 @@ (define tmp2 (make-mutex)) (mutex-lock! tmp2) (mutex-unlock! tmp2) +(set! tmp2 #f) ;; A program to prove if cooperation is working, or if it ;; is blocked by another thread. The (read) causes the main