4 ms·
> For example, if you have a stack variable and pass a reference to a short-lived thread, Rust will just throw an error, because there is no way for Rust to pro
by zozbot234 5y ago
> For example, if you have a stack variable and pass a reference to a short-lived thread, Rust will just throw an error, because there is no way for Rust to prove that the lifetime of the borrow is short enough (bounded from above) because Rust does not have linear types.
Rust has scoped threads for this use case. Generally this uses closures as opposed to lifetimes to "bound borrows from above" in a safe way.
- klodolph 5y agoRust has crossbeam, but it is not a complete solution to the problem. Scoped threads were removed.
- ssokolow 5y agoWould you mind elaborating? It was removed from the standard library ages ago, but `crossbeam::scope` appears to still be there in the newest release of crossbeam and the git repo.
- klodolph 5y agoUsing a scope for spawning threads is a solution to a narrow slice of a much larger problem.