Fix early join after start.

This commit is contained in:
Jeroen van Rijn
2025-06-21 11:47:00 +02:00
parent 8dc374a6ae
commit 1903d7211e
5 changed files with 75 additions and 75 deletions
+5 -6
View File
@@ -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) {