// 100,000 actors waiting for a message that never comes: the time to // spawn them, and the memory an idle actor takes (ADR 0028 measures the // peak resident set with `/usr/bin/time -f %M`). import std/io import std/process.{type Subject, type proc} fn spawn_all :: n: Int ready: Subject<()> -> () / { if n > 0 { let _ = process.spawn fn { let inbox: Subject = process.subject () process.send ready () let _ = process.receive_forever inbox } spawn_all (n - 1) ready } } fn wait_all :: ready: Subject<()> left: Int -> () / { if left > 0 { process.receive_forever ready wait_all ready (left - 1) } } pub fn main :: -> () / { let n = 100000 let ready = process.subject () spawn_all n ready wait_all ready n io.println (show n <> " actors waiting") } //> 100000 actors waiting