aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-08-26 22:42:56 +0100
committergingerBill <bill@gingerbill.org>2021-08-26 22:42:56 +0100
commit2f34f1283a067335d5738abe15997e6af5e3a600 (patch)
tree9c465696e20815ef81703170405a98eba558c402
parentf973d271cf41daa06d060f4c0e4f68effb253c68 (diff)
Make `thread_join` be more correct
-rw-r--r--src/threading.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/threading.cpp b/src/threading.cpp
index 7a802fd71..e9412b411 100644
--- a/src/threading.cpp
+++ b/src/threading.cpp
@@ -355,8 +355,8 @@ void gb__thread_run(Thread *t) {
#if defined(GB_SYSTEM_WINDOWS)
DWORD __stdcall internal_thread_proc(void *arg) {
Thread *t = cast(Thread *)arg;
+ t->is_running.store(true);
gb__thread_run(t);
- t->is_running.store(false);
return 0;
}
#else
@@ -369,8 +369,8 @@ void gb__thread_run(Thread *t) {
#endif
Thread *t = cast(Thread *)arg;
+ t->is_running.store(true);
gb__thread_run(t);
- t->is_running.store(false);
return NULL;
}
#endif
@@ -383,7 +383,6 @@ void thread_start_with_stack(Thread *t, ThreadProc *proc, void *user_data, isize
t->proc = proc;
t->user_data = user_data;
t->stack_size = stack_size;
- t->is_running.store(true);
#if defined(GB_SYSTEM_WINDOWS)
t->win32_handle = CreateThread(NULL, stack_size, internal_thread_proc, t, 0, NULL);
@@ -405,7 +404,9 @@ void thread_start_with_stack(Thread *t, ThreadProc *proc, void *user_data, isize
}
void thread_join(Thread *t) {
- if (!t->is_running.load()) return;
+ if (!t->is_running.load()) {
+ return;
+ }
#if defined(GB_SYSTEM_WINDOWS)
WaitForSingleObject(t->win32_handle, INFINITE);