From 4df811b0c4e16bfaf063a75f0864aacead2551c4 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sun, 17 Oct 2021 17:48:17 -0500 Subject: [PATCH] bugfixes with __atomic_wait --- core/alloc/heap.onyx | 2 +- core/intrinsics/atomics.onyx | 2 +- core/runtime/js.onyx | 2 ++ core/threads/thread.onyx | 5 ++++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/alloc/heap.onyx b/core/alloc/heap.onyx index b15d4ce2..ea17f995 100644 --- a/core/alloc/heap.onyx +++ b/core/alloc/heap.onyx @@ -15,7 +15,7 @@ Enable_Debug :: false #if runtime.Multi_Threading_Enabled { sync :: package core.sync - + heap_mutex: sync.Mutex } diff --git a/core/intrinsics/atomics.onyx b/core/intrinsics/atomics.onyx index ea449c6b..70cd2536 100644 --- a/core/intrinsics/atomics.onyx +++ b/core/intrinsics/atomics.onyx @@ -9,7 +9,7 @@ package core.intrinsics.atomics } // __atomic_wait is only valid for i32 and i64 -__atomic_wait :: (addr: ^$T, value: T, timeout: i64 = 0) -> i32 #intrinsic --- +__atomic_wait :: (addr: ^$T, value: T, timeout: i64 = -1) -> i32 #intrinsic --- __atomic_notify :: (addr: rawptr, maximum: i32 = 1) -> i32 #intrinsic --- __atomic_fence :: () -> void #intrinsic --- diff --git a/core/runtime/js.onyx b/core/runtime/js.onyx index 63aad0f5..083641fa 100644 --- a/core/runtime/js.onyx +++ b/core/runtime/js.onyx @@ -30,6 +30,8 @@ __exit :: (status: i32) -> void #foreign "host" "exit" --- } #export "_thread_exit" (id: i32) { + // raw_free(context.allocator, __stack_top); + thread.__exited(id); } } \ No newline at end of file diff --git a/core/threads/thread.onyx b/core/threads/thread.onyx index b7204115..c4597362 100644 --- a/core/threads/thread.onyx +++ b/core/threads/thread.onyx @@ -1,6 +1,7 @@ package core.thread use package core +use package core.intrinsics.atomics #private { thread_mutex : sync.Mutex; @@ -28,7 +29,7 @@ spawn :: (t: ^Thread, func: (rawptr) -> void, data: rawptr) { } join :: (t: ^Thread) { - while t.alive ---; + while t.alive do __atomic_wait(^t.id, t.id); } __initialize :: () { @@ -41,6 +42,8 @@ __exited :: (id: i32) { thread := thread_map->get(id); if thread != null { thread.alive = false; + __atomic_notify(^thread.id); + thread_map->delete(id); } } -- 2.25.1