// Parallel work: 64 actors each compute a Fibonacci number, on all // threads. Spreading them over the threads is the scheduler's job. import std/io import std/process.{type Subject, type proc} fn fib :: n: Int -> Int { if n < 2 { n } else { fib (n - 1) + fib (n - 2) } } fn start :: n: Int results: Subject -> () / { if n > 0 { let _ = process.spawn fn { process.send results (fib 32) } start (n - 1) results } } fn collect :: n: Int results: Subject acc: Int -> Int / { if n == 0 { acc } else { collect (n - 1) results (acc + process.receive_forever results) } } pub fn main :: -> () / { let results = process.subject () start 64 results io.println (show (collect 64 results 0)) } //> 139411776