summaryrefslogtreecommitdiff
path: root/libguile/threads.c
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2017-01-08 13:44:38 +0100
committerAndy Wingo <wingo@pobox.com>2017-01-08 13:44:38 +0100
commitdffe495d0de1466f62a91a6d74cc0f388e0f4f3f (patch)
treeeb8787d13e353592126b596407c4c34ce1ccceeb /libguile/threads.c
parent12eb7b8256f579fab60ebe0b38eb8788c1276eb8 (diff)
downloadguile-dffe495d0de1466f62a91a6d74cc0f388e0f4f3f.tar.gz
Exited threads retain less memory
* libguile/threads.c (on_thread_exit): Lessen excess retention.
Diffstat (limited to 'libguile/threads.c')
-rw-r--r--libguile/threads.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/libguile/threads.c b/libguile/threads.c
index 7d91a01da..da5b8141d 100644
--- a/libguile/threads.c
+++ b/libguile/threads.c
@@ -475,7 +475,9 @@ guilify_self_2 (SCM dynamic_state)
static void
on_thread_exit (void *v)
{
- /* This handler is executed in non-guile mode. */
+ /* This handler is executed in non-guile mode. Note that although
+ libgc isn't guaranteed to see thread-locals, for this thread-local
+ that isn't an issue as we have the all_threads list. */
scm_i_thread *t = (scm_i_thread *) v, **tp;
t->exited = 1;
@@ -506,11 +508,20 @@ on_thread_exit (void *v)
scm_i_pthread_mutex_unlock (&thread_admin_mutex);
- if (t->vp)
- {
- scm_i_vm_free_stack (t->vp);
- t->vp = NULL;
- }
+ /* Although this thread has exited, the thread object might still be
+ alive. Release unused memory. */
+ t->freelists = NULL;
+ t->pointerless_freelists = NULL;
+ t->dynamic_state = NULL;
+ t->dynstack.base = NULL;
+ t->dynstack.top = NULL;
+ t->dynstack.limit = NULL;
+ {
+ struct scm_vm *vp = t->vp;
+ t->vp = NULL;
+ if (vp)
+ scm_i_vm_free_stack (vp);
+ }
#if SCM_USE_PTHREAD_THREADS
GC_unregister_my_thread ();