5ec755743d
- C runtime: ucontext-based coroutines (bux_async_spawn/yield/await/run) - Round-robin scheduler in bux_async_run() manages ready queue - spawn Func() without args → bux_async_spawn() creates coroutine - await → blocks/yields until coroutine completes - async func → emitted as regular C function, runs on dedicated stack - Interleaved execution: multiple coroutines yield cooperatively - Example: examples/async.bux demonstrates WorkA/WorkB interleaving - All 20 examples pass, selfhost build works
33 lines
730 B
Plaintext
33 lines
730 B
Plaintext
import Std::Io::PrintLine;
|
|
|
|
extern func bux_async_yield();
|
|
extern func bux_async_run();
|
|
extern func bux_async_spawn(fn: *void) -> *void;
|
|
extern func bux_async_await(handle: *void);
|
|
|
|
async func WorkA() {
|
|
PrintLine("WorkA: step 1");
|
|
bux_async_yield();
|
|
PrintLine("WorkA: step 2");
|
|
bux_async_yield();
|
|
PrintLine("WorkA: done");
|
|
}
|
|
|
|
async func WorkB() {
|
|
PrintLine("WorkB: step 1");
|
|
bux_async_yield();
|
|
PrintLine("WorkB: step 2");
|
|
bux_async_yield();
|
|
PrintLine("WorkB: done");
|
|
}
|
|
|
|
func Main() -> int {
|
|
PrintLine("Main: start");
|
|
let h1: *void = spawn WorkA();
|
|
let h2: *void = spawn WorkB();
|
|
bux_async_await(h1);
|
|
bux_async_await(h2);
|
|
PrintLine("Main: all done");
|
|
return 0;
|
|
}
|