Fix joining non-Started threads from blocking main thread

This commit is contained in:
Feoramund
2024-05-10 17:24:45 -04:00
parent 2250eb3e78
commit 33c6f75a2e
2 changed files with 19 additions and 2 deletions
+9
View File
@@ -36,6 +36,10 @@ _create :: proc(procedure: Thread_Proc, priority: Thread_Priority) -> ^Thread {
sync.wait(&t.cond, &t.mutex)
}
if .Joined in t.flags {
return nil
}
when ODIN_OS != .Darwin {
// Enable thread's cancelability.
if can_set_thread_cancel_state {
@@ -143,6 +147,11 @@ _join :: proc(t: ^Thread) {
if res, ok := CAS(&t.flags, unjoined, joined); res == joined && !ok {
return
}
// Prevent non-started threads from blocking main thread with initial wait
// condition.
if .Started not_in unjoined {
_start(t)
}
unix.pthread_join(t.unix_thread, nil)
}