
louise
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#1199 · main · 10 min 33 s
1Étoiles
0Forks
0Issues
| 1 | // A builder past the send walk's copy limit (4 KiB), captured by spawned |
| 2 | // actors, is promoted to shared: its count is negative and changed |
| 3 | // atomically by each holder. Each actor builds and appends to it in a |
| 4 | // loop, so the `unique` tests of `std/bytes`' builder (builder.rs: |
| 5 | // `reserve`, `tl_bytes_build`, `tl_bytes_build_string`) read a count other |
| 6 | // threads change. Under TSan (scripts/tsan.sh), a plain read there is a |
| 7 | // data race; it must be an atomic one (`heap::rc`), as `array.rs`'s is. |
| 8 | |
| 9 | import std/bytes |
| 10 | import std/io |
| 11 | import std/process.{type proc} |
| 12 | import std/string |
| 13 | |
| 14 | fn grow :: b: bytes.Builder n: Int -> bytes.Builder |
| 15 | { |
| 16 | if n == 0 |
| 17 | { |
| 18 | b |
| 19 | } |
| 20 | else |
| 21 | { |
| 22 | grow (bytes.append_byte b 65) (n - 1) |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | fn work :: b: bytes.Builder n: Int acc: Int -> Int |
| 27 | { |
| 28 | if n == 0 |
| 29 | { |
| 30 | acc |
| 31 | } |
| 32 | else |
| 33 | { |
| 34 | let built = bytes.build b |
| 35 | let s = bytes.build_string b |
| 36 | let c = bytes.append_byte b 66 |
| 37 | work |
| 38 | b |
| 39 | (n - 1) |
| 40 | ( acc + bytes.length built + string.length s |
| 41 | + bytes.length (bytes.build c) |
| 42 | ) |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | pub fn main :: -> () / <io, proc> |
| 47 | { |
| 48 | let b = grow (bytes.builder ()) 8000 |
| 49 | let done = process.subject () |
| 50 | let _ = |
| 51 | { |
| 52 | use <- process.spawn |
| 53 | process.send done (work b 300 0) |
| 54 | } |
| 55 | let _ = |
| 56 | { |
| 57 | use <- process.spawn |
| 58 | process.send done (work b 300 0) |
| 59 | } |
| 60 | let _ = |
| 61 | { |
| 62 | use <- process.spawn |
| 63 | process.send done (work b 300 0) |
| 64 | } |
| 65 | let _ = |
| 66 | { |
| 67 | use <- process.spawn |
| 68 | process.send done (work b 300 0) |
| 69 | } |
| 70 | let t = |
| 71 | process.receive_forever done + process.receive_forever done |
| 72 | + process.receive_forever done |
| 73 | + process.receive_forever done |
| 74 | io.println (show t) |
| 75 | } |
| 76 | //> 28801200 |