// Churn: 64 actors each spawn 2,000 short-lived children, one at a time, // on all threads. Each child answers once and finishes: every spawn and // every finish takes the actor table's write lock and the stack pool // (issue gabla108/louise#131). import std/io import std/process.{type Subject, type proc} fn children :: inbox: Subject i: Int n: Int total: Int -> Int / { if i == n { total } else { let _ = process.spawn fn { process.send inbox (i * 2) } children inbox (i + 1) n (total + process.receive_forever inbox) } } fn parents :: k: Int report: Subject n: Int -> () / { if k > 0 { let _ = process.spawn fn { let inbox = process.subject () process.send report (children inbox 0 n 0) } parents (k - 1) report n } } fn collect :: from: Subject left: Int total: Int -> Int / { if left == 0 { total } else { collect from (left - 1) (total + process.receive_forever from) } } pub fn main :: -> () / { let report = process.subject () parents 64 report 2000 io.println (show (collect report 64 0)) } //> 255872000