louise
The Louise language: compiler, runtime, std, tooling
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#125 · main · 16 min 13 s
0Étoiles
0Forks
40Issues
| 1 | // 100,000 actors waiting for a message that never comes: the time to |
| 2 | // spawn them, and the memory an idle actor takes (ADR 0028 measures the |
| 3 | // peak resident set with `/usr/bin/time -f %M`). |
| 4 | |
| 5 | import std/io |
| 6 | import std/process.{type Subject, type proc} |
| 7 | |
| 8 | fn spawn_all :: n: Int ready: Subject<()> -> () / <proc> |
| 9 | { |
| 10 | if n > 0 |
| 11 | { |
| 12 | let _ = |
| 13 | process.spawn |
| 14 | fn |
| 15 | { |
| 16 | let inbox: Subject<Int> = process.subject () |
| 17 | process.send ready () |
| 18 | let _ = process.receive_forever inbox |
| 19 | } |
| 20 | spawn_all (n - 1) ready |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | fn wait_all :: ready: Subject<()> left: Int -> () / <proc> |
| 25 | { |
| 26 | if left > 0 |
| 27 | { |
| 28 | process.receive_forever ready |
| 29 | wait_all ready (left - 1) |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | pub fn main :: -> () / <io, proc> |
| 34 | { |
| 35 | let n = 100000 |
| 36 | let ready = process.subject () |
| 37 | spawn_all n ready |
| 38 | wait_all ready n |
| 39 | io.println (show n <> " actors waiting") |
| 40 | } |
| 41 | //> 100000 actors waiting |