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
+10 -2
View File
@@ -24,6 +24,10 @@ _create :: proc(procedure: Thread_Proc, priority: Thread_Priority) -> ^Thread {
__windows_thread_entry_proc :: proc "system" (t_: rawptr) -> win32.DWORD {
t := (^Thread)(t_)
if .Joined in t.flags {
return 0
}
t.id = sync.current_thread_id()
{
@@ -93,11 +97,15 @@ _join :: proc(t: ^Thread) {
return
}
t.flags += {.Joined}
if .Started not_in t.flags {
_start(t)
}
win32.WaitForSingleObject(t.win32_thread, win32.INFINITE)
win32.CloseHandle(t.win32_thread)
t.win32_thread = win32.INVALID_HANDLE
t.flags += {.Joined}
}
_join_multiple :: proc(threads: ..^Thread) {