Skip to content

Commit 4158f90

Browse files
author
Stjepan Glavina
committed
Expand prior art with some Crossbeam history
1 parent a76bcf5 commit 4158f90

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

text/0000-scoped-threads.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,30 @@ Crossbeam has had
252252
[scoped threads](https://docs.rs/crossbeam/0.7.1/crossbeam/thread/index.html)
253253
since Rust 1.0.
254254

255+
There are two designs Crossbeam's scoped threads went through. The old one is from
256+
the time `thread::scoped()` got removed and we wanted a sound alternative for the
257+
Rust 1.0 era. The new one is from the last year's big revamp:
258+
259+
* Old: https://docs.rs/crossbeam/0.2.12/crossbeam/fn.scope.html
260+
* New: https://docs.rs/crossbeam/0.7.1/crossbeam/fn.scope.html
261+
262+
There are several differences between old and new scoped threads:
263+
264+
1. `scope()` now returns a `thread::Result<T>` rather than `T`. This is because
265+
panics in the old design were just silently ignored, which is not good.
266+
By returning a `Result`, the user can handle panics in whatever way they want.
267+
268+
2. The closure passed to `Scope::spawn()` now takes a `&Scope<'env>` argument that
269+
allows one to spawn nested threads, which was not possible with the old design.
270+
Rayon similarly passes a reference to child tasks.
271+
272+
3. We removed `Scope::defer()` because it is not really useful, had bugs, and had
273+
non-obvious behavior.
274+
275+
4. `ScopedJoinHandle` got parametrized over `'scope` in order to prevent it from
276+
escaping the scope. However, it turns out this is not really necessary for
277+
soundness and was just a conservative safeguard.
278+
255279
Rayon also has [scopes](https://docs.rs/rayon/1.0.3/rayon/struct.Scope.html),
256280
but they work on a different abstraction level - Rayon spawns tasks rather than
257281
threads. Its API is almost the same as proposed in this RFC, the only

0 commit comments

Comments
 (0)