#if runtime.Multi_Threading_Enabled {
sync :: package core.sync
-
+
heap_mutex: sync.Mutex
}
}
// __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 ---
}
#export "_thread_exit" (id: i32) {
+ // raw_free(context.allocator, __stack_top);
+
thread.__exited(id);
}
}
\ No newline at end of file
package core.thread
use package core
+use package core.intrinsics.atomics
#private {
thread_mutex : sync.Mutex;
}
join :: (t: ^Thread) {
- while t.alive ---;
+ while t.alive do __atomic_wait(^t.id, t.id);
}
__initialize :: () {
thread := thread_map->get(id);
if thread != null {
thread.alive = false;
+ __atomic_notify(^thread.id);
+
thread_map->delete(id);
}
}