mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 14:48:47 +00:00
Fix early join after start.
This commit is contained in:
@@ -13,6 +13,7 @@ Thread_Os_Specific :: struct {
|
||||
win32_thread: win32.HANDLE,
|
||||
win32_thread_id: win32.DWORD,
|
||||
mutex: sync.Mutex,
|
||||
start_ok: sync.Sema,
|
||||
}
|
||||
|
||||
_thread_priority_map := [Thread_Priority]i32{
|
||||
@@ -27,8 +28,8 @@ _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 sync.atomic_load(&t.flags) {
|
||||
return 0
|
||||
for (.Started not_in sync.atomic_load(&t.flags)) {
|
||||
sync.wait(&t.start_ok)
|
||||
}
|
||||
|
||||
{
|
||||
@@ -102,16 +103,15 @@ _join :: proc(t: ^Thread) {
|
||||
return
|
||||
}
|
||||
|
||||
t.flags += {.Joined}
|
||||
|
||||
if .Started not_in t.flags {
|
||||
t.flags += {.Started}
|
||||
win32.ResumeThread(t.win32_thread)
|
||||
for (.Started not_in sync.atomic_load(&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) {
|
||||
@@ -135,6 +135,7 @@ _join_multiple :: proc(threads: ..^Thread) {
|
||||
for t in threads {
|
||||
win32.CloseHandle(t.win32_thread)
|
||||
t.win32_thread = win32.INVALID_HANDLE
|
||||
t.flags += {.Joined}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user