From 1e6419b5b7bdafe3f1d1a2b4321238b6257c44e6 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Wed, 28 Aug 2024 16:22:38 +0200 Subject: [PATCH] fix zombie thread leak in thread self cleanup --- core/sys/unix/pthread_unix.odin | 2 ++ core/thread/thread_unix.odin | 3 +++ 2 files changed, 5 insertions(+) diff --git a/core/sys/unix/pthread_unix.odin b/core/sys/unix/pthread_unix.odin index 68a0859b4..26a21e629 100644 --- a/core/sys/unix/pthread_unix.odin +++ b/core/sys/unix/pthread_unix.odin @@ -27,6 +27,8 @@ foreign pthread { pthread_equal :: proc(a, b: pthread_t) -> b32 --- + pthread_detach :: proc(t: pthread_t) -> c.int --- + sched_get_priority_min :: proc(policy: c.int) -> c.int --- sched_get_priority_max :: proc(policy: c.int) -> c.int --- diff --git a/core/thread/thread_unix.odin b/core/thread/thread_unix.odin index 3d25b1909..ddc47244c 100644 --- a/core/thread/thread_unix.odin +++ b/core/thread/thread_unix.odin @@ -69,6 +69,9 @@ _create :: proc(procedure: Thread_Proc, priority: Thread_Priority) -> ^Thread { sync.unlock(&t.mutex) if .Self_Cleanup in sync.atomic_load(&t.flags) { + res := unix.pthread_detach(t.unix_thread) + assert_contextless(res == 0) + t.unix_thread = {} // NOTE(ftphikari): It doesn't matter which context 'free' received, right? context = {}