Add API for freeing thread_local state

This commit is contained in:
Feoramund
2024-08-26 05:56:22 -04:00
parent 8de1e88c4f
commit d338642dc4
3 changed files with 44 additions and 2 deletions
+5 -1
View File
@@ -2,6 +2,7 @@
// +private
package thread
import "base:runtime"
import "core:sync"
import "core:sys/unix"
import "core:time"
@@ -55,7 +56,10 @@ _create :: proc(procedure: Thread_Proc, priority: Thread_Priority) -> ^Thread {
// Here on Unix, we start the OS thread in a running state, and so we manually have it wait on a condition
// variable above. We must perform that waiting BEFORE we select the context!
context = _select_context_for_thread(init_context)
defer _maybe_destroy_default_temp_allocator(init_context)
defer {
_maybe_destroy_default_temp_allocator(init_context)
runtime.run_thread_local_cleaners()
}
t.procedure(t)
}
+5 -1
View File
@@ -3,6 +3,7 @@
package thread
import "base:intrinsics"
import "base:runtime"
import "core:sync"
import win32 "core:sys/windows"
@@ -39,7 +40,10 @@ _create :: proc(procedure: Thread_Proc, priority: Thread_Priority) -> ^Thread {
// Here on Windows, the thread is created in a suspended state, and so we can select the context anywhere before the call
// to t.procedure().
context = _select_context_for_thread(init_context)
defer _maybe_destroy_default_temp_allocator(init_context)
defer {
_maybe_destroy_default_temp_allocator(init_context)
runtime.run_thread_local_cleaners()
}
t.procedure(t)
}