test: add green thread integration test

Also fix runtime scheduler bugs:
- g_task_creating was thread-local but set on main thread and read on worker
- g_scheduler_context was global shared by all workers instead of per-thread
This commit is contained in:
2026-06-10 19:48:39 +03:00
parent 9cd0580832
commit 2824d25369
3 changed files with 39 additions and 5 deletions
+29
View File
@@ -0,0 +1,29 @@
import Std::Task;
import Std::String;
func Worker(id: int) {
PrintLine(String_Concat(String_Concat("Worker ", String_FromInt(id)), " starting"));
Task_Sleep(50);
PrintLine(String_Concat(String_Concat("Worker ", String_FromInt(id)), " done"));
}
func Main() -> int {
PrintLine("=== Green Thread Test ===");
Task_Init(4);
let h1: TaskHandle = Task_Spawn(Worker as *void, 1 as *void);
let h2: TaskHandle = Task_Spawn(Worker as *void, 2 as *void);
let h3: TaskHandle = Task_Spawn(Worker as *void, 3 as *void);
PrintLine("Waiting for tasks...");
Task_Wait(h1);
Task_Wait(h2);
Task_Wait(h3);
Task_Shutdown();
PrintLine("=== All tasks complete ===");
return 0;
}