11. 並發
執行緒由 std/thread.zc 提供,基於 pthreads。Thread::spawn 在新執行緒中執行一個函數或閉包,join 等待它結束。
import "std/thread.zc"
import "std/io.zc"
fn fetch_data(id: int) {
println(f"Worker running in the background");
}
fn main() {
let t = Thread::spawn(fn() {
fetch_data(1);
}).unwrap();
t.join();
}