Browse Source

fix zombie thread leak in thread self cleanup

Laytan Laats 1 year ago
parent
commit
1e6419b5b7
2 changed files with 5 additions and 0 deletions
  1. 2 0
      core/sys/unix/pthread_unix.odin
  2. 3 0
      core/thread/thread_unix.odin

+ 2 - 0
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 ---
 

+ 3 - 0
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 = {}