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 | // Churn: 64 actors each spawn 2,000 short-lived children, one at a time, |
| 2 | // on all threads. Each child answers once and finishes: every spawn and |
| 3 | // every finish takes the actor table's write lock and the stack pool |
| 4 | // (issue gabla108/louise#131). |
| 5 | |
| 6 | import std/io |
| 7 | import std/process.{type Subject, type proc} |
| 8 | |
| 9 | fn children :: inbox: Subject<Int> i: Int n: Int total: Int -> Int / <proc> |
| 10 | { |
| 11 | if i == n |
| 12 | { |
| 13 | total |
| 14 | } |
| 15 | else |
| 16 | { |
| 17 | let _ = process.spawn fn { process.send inbox (i * 2) } |
| 18 | children inbox (i + 1) n (total + process.receive_forever inbox) |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | fn parents :: k: Int report: Subject<Int> n: Int -> () / <proc> |
| 23 | { |
| 24 | if k > 0 |
| 25 | { |
| 26 | let _ = |
| 27 | process.spawn |
| 28 | fn |
| 29 | { |
| 30 | let inbox = process.subject () |
| 31 | process.send report (children inbox 0 n 0) |
| 32 | } |
| 33 | parents (k - 1) report n |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | fn collect :: from: Subject<Int> left: Int total: Int -> Int / <proc> |
| 38 | { |
| 39 | if left == 0 |
| 40 | { |
| 41 | total |
| 42 | } |
| 43 | else |
| 44 | { |
| 45 | collect from (left - 1) (total + process.receive_forever from) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | pub fn main :: -> () / <io, proc> |
| 50 | { |
| 51 | let report = process.subject () |
| 52 | parents 64 report 2000 |
| 53 | io.println (show (collect report 64 0)) |
| 54 | } |
| 55 | //> 255872000 |