Deconstructing thread::scope#120
Deconstructing thread::scope#120listochkin wants to merge 4 commits intothread-spawn-send-arc-mutexfrom
thread::scope#120Conversation
|
The part discussing covariance-contravariance will be in a separate deck |
jonathanpallant
left a comment
There was a problem hiding this comment.
Another great deck. Loved it. Just some very minor notes.
| * `F: for<'scope> FnOnce(&'scope Scope<'scope, 'env>) -> T` | ||
| * `'scope` is a *Higher-Rank Trait Bound* - it describes *all possible* lifetimes that closure can observe | ||
| * `fn scope<'env, F, T>(f: F) -> T` | ||
| * the function observes *some* lifetime `'env` |
There was a problem hiding this comment.
| * the function observes *some* lifetime `'env` | |
| * the function observes *some* lifetime `'env` |
In the lifetimes deck we tried to distinguish between a lifetime (which is a property of a value, marking the time between its creation and its destruction as observed at compile-time), and a lifetime tag/annotation/specifier which is what we add to references to tag or annotate the lifetime of the value they refer to so we can tag/annotate other references as having a must-not-outlive relationship.
| left_sum = left.iter().sum(); | ||
| }); | ||
| // ERROR: closure may outlive the current function | ||
| let mut right_sum = 0; |
There was a problem hiding this comment.
I think I prefer having examples which compile and run, but where the 'bad code' is commented out.
| } | ||
| ``` | ||
|
|
||
| ## How `scope` function waits for all threads to finish? |
There was a problem hiding this comment.
| ## How `scope` function waits for all threads to finish? | |
| ## How does `fn scope()` wait for all threads to finish? |
| } | ||
| } | ||
| ``` | ||
|
|
There was a problem hiding this comment.
Links to stdlib source code here would be neat.
Co-authored-by: Jonathan Pallant <jonathan.pallant@ferrous-systems.com>
ee0a280 to
29a65a6
Compare
2e15439 to
37dc913
Compare
d0d6848 to
d029d6e
Compare
Making this PR against
thread::spawnbranch to better visualize the diff