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#121 · main · 16 min 23 s
0Étoiles
0Forks
40Issues
| 1 | // Selective receive under unrelated traffic: `main` makes 50,000 calls, |
| 2 | // each waiting for its reply on a subject of its own, while 4 actors keep |
| 3 | // sending to its other subject. A message a receive does not wait for may |
| 4 | // wake it (ADR 0028); it then waits again. |
| 5 | |
| 6 | import std/io |
| 7 | import std/process.{type Subject, type proc} |
| 8 | |
| 9 | fn server :: requests: Subject<Subject<Int>> n: Int -> () / <proc> |
| 10 | { |
| 11 | let reply = process.receive_forever requests |
| 12 | process.send reply n |
| 13 | server requests (n + 1) |
| 14 | } |
| 15 | |
| 16 | fn flood :: to: Subject<Int> n: Int -> () / <proc> |
| 17 | { |
| 18 | if n > 0 |
| 19 | { |
| 20 | process.send to n |
| 21 | flood to (n - 1) |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | fn calls :: requests: Subject<Subject<Int>> n: Int total: Int -> Int / <proc> |
| 26 | { |
| 27 | if n == 0 |
| 28 | { |
| 29 | total |
| 30 | } |
| 31 | else |
| 32 | { |
| 33 | let reply = process.subject () |
| 34 | process.send requests reply |
| 35 | calls requests (n - 1) (total + process.receive_forever reply) |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | fn drain :: from: Subject<Int> left: Int total: Int -> Int / <proc> |
| 40 | { |
| 41 | if left == 0 |
| 42 | { |
| 43 | total |
| 44 | } |
| 45 | else |
| 46 | { |
| 47 | drain from (left - 1) (total + process.receive_forever from) |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | fn spawn_floods :: k: Int to: Subject<Int> -> () / <proc> |
| 52 | { |
| 53 | if k > 0 |
| 54 | { |
| 55 | let _ = process.spawn fn { flood to 50000 } |
| 56 | spawn_floods (k - 1) to |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | pub fn main :: -> () / <io, proc> |
| 61 | { |
| 62 | let ready = process.subject () |
| 63 | let noise = process.subject () |
| 64 | let _ = |
| 65 | process.spawn |
| 66 | fn |
| 67 | { |
| 68 | let requests = process.subject () |
| 69 | process.send ready requests |
| 70 | server requests 0 |
| 71 | } |
| 72 | let requests = process.receive_forever ready |
| 73 | spawn_floods 4 noise |
| 74 | let replies = calls requests 50000 0 |
| 75 | io.println (show replies <> " " <> show (drain noise (4 * 50000) 0)) |
| 76 | } |
| 77 | //> 1249975000 5000100000 |