aboutsummaryrefslogtreecommitdiff
path: root/core/thread/thread_windows.odin
diff options
context:
space:
mode:
Diffstat (limited to 'core/thread/thread_windows.odin')
-rw-r--r--core/thread/thread_windows.odin15
1 files changed, 8 insertions, 7 deletions
diff --git a/core/thread/thread_windows.odin b/core/thread/thread_windows.odin
index 438f79c6f..358e3e7f1 100644
--- a/core/thread/thread_windows.odin
+++ b/core/thread/thread_windows.odin
@@ -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}
}
}