From 1903d7211ee42286cb45aa77a7c97e3bb131e4d5 Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Sat, 21 Jun 2025 11:47:00 +0200 Subject: Fix early join after start. --- core/thread/thread_unix.odin | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'core/thread/thread_unix.odin') diff --git a/core/thread/thread_unix.odin b/core/thread/thread_unix.odin index 7be5103ae..1431442a9 100644 --- a/core/thread/thread_unix.odin +++ b/core/thread/thread_unix.odin @@ -29,14 +29,10 @@ _create :: proc(procedure: Thread_Proc, priority: Thread_Priority) -> ^Thread { t.id = sync.current_thread_id() - if .Started not_in sync.atomic_load(&t.flags) { + for (.Started not_in sync.atomic_load(&t.flags)) { sync.wait(&t.start_ok) } - if .Joined in sync.atomic_load(&t.flags) { - return nil - } - // Enable thread's cancelability. // NOTE(laytan): Darwin does not correctly/fully support all of this, not doing this does // actually make pthread_cancel work in the capacity of my tests, while executing this would @@ -148,10 +144,13 @@ _join :: proc(t: ^Thread) { // Prevent non-started threads from blocking main thread with initial wait // condition. - if .Started not_in sync.atomic_load(&t.flags) { + for (.Started not_in sync.atomic_load(&t.flags)) { _start(t) } + posix.pthread_join(t.unix_thread, nil) + + t.flags += {.Joined} } _join_multiple :: proc(threads: ..^Thread) { -- cgit v1.2.3