},
alert: function(strptr, strlen) {
- const decoder = new TextDecoder();
- const data = new Uint8Array(window.ONYX_MEMORY.buffer, strptr, strlen);
- const str = decoder.decode(data);
+ const str = onyx_decode_text(strptr, strlen);
window.alert(str);
},
use package core.intrinsics.atomics
- t, t2: thread.Thread;
- thread.spawn(^t, (_: ^i32) {
+ #persist #thread_local t : thread.Thread;
+ #persist #thread_local t2 : thread.Thread;
+ #persist barrier : sync.Barrier;
+ sync.barrier_init(^barrier, 2);
+
+ thread.spawn(^t, null, (_: ^i32) {
printf("Hello from another thread!\n");
for i: 1000 {
- __atomic_wait(_, 0, 1000000000);
+ sync.barrier_wait(^barrier);
printf("Hello from another thread! {}\n", i);
}
+ });
- }, null);
-
- thread.spawn(^t2, (_: ^i32) {
+ thread.spawn(^t2, null, (_: ^i32) {
i := 1;
while true {
i *= 2;
__atomic_wait(_, 0, 1000000000);
+ sync.barrier_wait(^barrier);
debug_log(.Warning, "Debug message: {}\n", i);
}
- }, null);
+ });
}
handle_event :: (event: ^events.Event) {