tobogganSe connecter

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.

55 lignes · 1167 octetsBrut · Historique
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 #131).
5
6import std/io
7import std/process.{type Subject, type proc}
8
9fn 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
22fn 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
37fn 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
49pub 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