-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathepisode.yml
55 lines (54 loc) · 3.24 KB
/
episode.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
number: 9
title: Go vs Rust - Concurrency and Race Conditions
id: B5xYBrxVSiE
intro: It's hard to put into words what I like about Rust. Easier to show with a quick example about concurrency and borrowing.
details: >
Capturing the "Magic of Rust" is not easy. Luckily, I found a simpler
way: show how Rust prevents race-conditions and guides us towards a safe,
idiomatic solution. We will port a little Go CLI tool to Rust and compare
both solutions in terms of safety, error handling, and concurrency patterns.
keywords:
- race-conditions
- ownership
- mutex
- concurrency
- rayon
- golang
- rustlang
notes:
- "Go in Practice book by Matt Butcher and Matt Farina (Manning Publications, 2016): https://www.manning.com/books/go-in-practice"
- "Go in Practice example source code:
https://github.com/Masterminds/go-in-practice"
- "Golang provides tooling to help detect race conditions. E.g. try `go run --race` (see 'Go in Practice, p.70')"
- "Explanation of the Rustlang race-condition prevention: https://stackoverflow.com/questions/30559073/cannot-borrow-captured-outer-variable-in-an-fn-closure-as-mutable"
- "Amazing article about Rustlang iterator patterns by Karol Kuczmarski:
http://xion.io/post/code/rust-iter-patterns.html"
- "for_each method:
https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.for_each"
- "[std::sync::Mutex](https://doc.rust-lang.org/std/sync/struct.Mutex.html)"
- "Golang sync.Waitgroup: https://golang.org/pkg/sync/#WaitGroup"
- "rayon crate for easy parallelism: https://github.com/rayon-rs/rayon"
- "partition method: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.partition"
errata:
- "[killercup](https://github.com/killercup) added [an alternative approach](https://github.com/hello-rust/show/pull/45) that creates one hashmap per file and uses Rayon's reduce to unify them."
- "[euantorano](https://github.com/euantorano) provided [an alternative Go approach to counting words](https://github.com/hello-rust/show/pull/46)."
- |
[killercup](https://github.com/killercup) added [benchmarks](https://github.com/hello-rust/show/pull/48) because <s>he seems to have too much free time at his hands</s> he was curios and people kept asking.
Here's a quick preview (but also run them on your own machine!):
![](https://cdn.rawgit.com/hello-rust/show/a8de0d77a8cb2672fe1f37f4d9251950038b7b50/episode/9/bench/results/ep9-violin.svg)
metas:
- "Color scheme: JetJet Alternate for VSCode"
licenses:
- "Comedic Boing, A.wav by InspectorJ (www.jshaw.co.uk) of Freesound.org"
- "Using 188709__setuniman__thoughts-1a37 by Setuniman (https://freesound.org/people/Setuniman/packs/9857/)"
- "Yay sound by jbeetle https://freesound.org/people/jbeetle/sounds/274510/"
- "piano-improv-prog-clumsy-raucous.wav by newagesoup https://freesound.org/people/newagesoup/sounds/341352/"
- "[Crayon designed by Terdpongvector](https://www.freepik.com/free-vector/school-stuff-collection_1060700.htm)"
chapters:
- "1:28 Golang code"
- "5:41 Trying to run our concurrent Go code"
- "8:31 What I don't like about concurrent Go code"
- "9:38 Rust code"
- "15:36 From sequential to concurrent code"
- "23:23 The beauty of Rust"
- "28:05 Handling errors in for_each"