@@ -252,6 +252,30 @@ Crossbeam has had
252
252
[ scoped threads] ( https://docs.rs/crossbeam/0.7.1/crossbeam/thread/index.html )
253
253
since Rust 1.0.
254
254
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
+
255
279
Rayon also has [ scopes] ( https://docs.rs/rayon/1.0.3/rayon/struct.Scope.html ) ,
256
280
but they work on a different abstraction level - Rayon spawns tasks rather than
257
281
threads. Its API is almost the same as proposed in this RFC, the only
0 commit comments