fix zombie thread leak in thread self cleanup

This commit is contained in:
Laytan Laats
2024-08-28 16:22:38 +02:00
parent ef66f96cf2
commit 1e6419b5b7
2 changed files with 5 additions and 0 deletions

View File

@@ -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 ---

View File

@@ -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 = {}