| Age | Commit message (Collapse) | Author | Lines | |
|---|---|---|---|---|
| 2022-12-05 | fix dupe word typos | Rageking8 | -1/+1 | |
| 2022-06-27 | fix data race in thread::scope | Ralf Jung | -4/+6 | |
| 2022-06-20 | Improve docs for `is_running` to explain use case | Josh Triplett | -3/+4 | |
| 2022-06-11 | Stabilize scoped threads. | Mara Bos | -8/+10 | |
| 2022-03-30 | Don't stabilize ScopedJoinHandle::is_finished yet. | Mara Bos | -1/+0 | |
| 2022-03-19 | Stabilize thread::is_finished | Jubilee Young | -1/+1 | |
| 2022-03-10 | Use implicit capture syntax in format_args | T-O-R-U-S | -1/+1 | |
| This updates the standard library's documentation to use the new syntax. The documentation is worthwhile to update as it should be more idiomatic (particularly for features like this, which are nice for users to get acquainted with). The general codebase is likely more hassle than benefit to update: it'll hurt git blame, and generally updates can be done by folks updating the code if (and when) that makes things more readable with the new format. A few places in the compiler and library code are updated (mostly just due to already having been done when this commit was first authored). | ||||
| 2022-03-09 | Add documentation about lifetimes to thread::scope. | Mara Bos | -0/+18 | |
| 2022-03-08 | Rollup merge of #94559 - m-ou-se:thread-scope-spawn-closure-without-arg, ↵ | Matthias Krüger | -21/+23 | |
| r=Mark-Simulacrum Remove argument from closure in thread::Scope::spawn. This implements ```@danielhenrymantilla's``` [suggestion](https://github.com/rust-lang/rust/issues/93203#issuecomment-1040798286) for improving the scoped threads interface. Summary: The `Scope` type gets an extra lifetime argument, which represents basically its own lifetime that will be used in `&'scope Scope<'scope, 'env>`: ```diff - pub struct Scope<'env> { .. }; + pub struct Scope<'scope, 'env: 'scope> { .. } pub fn scope<'env, F, T>(f: F) -> T where - F: FnOnce(&Scope<'env>) -> T; + F: for<'scope> FnOnce(&'scope Scope<'scope, 'env>) -> T; ``` This simplifies the `spawn` function, which now no longer passes an argument to the closure you give it, and now uses the `'scope` lifetime for everything: ```diff - pub fn spawn<'scope, F, T>(&'scope self, f: F) -> ScopedJoinHandle<'scope, T> + pub fn spawn<F, T>(&'scope self, f: F) -> ScopedJoinHandle<'scope, T> where - F: FnOnce(&Scope<'env>) -> T + Send + 'env, + F: FnOnce() -> T + Send + 'scope, - T: Send + 'env; + T: Send + 'scope; ``` The only difference the user will notice, is that their closure now takes no arguments anymore, even when spawning threads from spawned threads: ```diff thread::scope(|s| { - s.spawn(|_| { + s.spawn(|| { ... }); - s.spawn(|s| { + s.spawn(|| { ... - s.spawn(|_| ...); + s.spawn(|| ...); }); }); ``` <details><summary>And, as a bonus, errors get <em>slightly</em> better because now any lifetime issues point to the outermost <code>s</code> (since there is only one <code>s</code>), rather than the innermost <code>s</code>, making it clear that the lifetime lasts for the entire <code>thread::scope</code>. </summary> ```diff error[E0373]: closure may outlive the current function, but it borrows `a`, which is owned by the current function --> src/main.rs:9:21 | - 7 | s.spawn(|s| { - | - has type `&Scope<'1>` + 6 | thread::scope(|s| { + | - lifetime `'1` appears in the type of `s` 9 | s.spawn(|| println!("{:?}", a)); // might run after `a` is dropped | ^^ - `a` is borrowed here | | | may outlive borrowed value `a` | note: function requires argument type to outlive `'1` --> src/main.rs:9:13 | 9 | s.spawn(|| println!("{:?}", a)); // might run after `a` is dropped | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: to force the closure to take ownership of `a` (and any other referenced variables), use the `move` keyword | 9 | s.spawn(move || println!("{:?}", a)); // might run after `a` is dropped | ++++ " ``` </details> The downside is that the signature of `scope` and `Scope` gets slightly more complex, but in most cases the user wouldn't need to write those, as they just use the argument provided by `thread::scope` without having to name its type. Another downside is that this does not work nicely in Rust 2015 and Rust 2018, since in those editions, `s` would be captured by reference and not by copy. In those editions, the user would need to use `move ||` to capture `s` by copy. (Which is what the compiler suggests in the error.) | ||||
| 2022-03-07 | Use `f` instead of `|| f()`. | Mara Bos | -1/+1 | |
| Co-authored-by: Mark Rousskov <mark.simulacrum@gmail.com> | ||||
| 2022-03-04 | Use '_ for irrelevant lifetimes in Debug impl. | Mara Bos | -1/+1 | |
| Co-authored-by: Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com> | ||||
| 2022-03-03 | Remove argument from closure in thread::Scope::spawn. | Mara Bos | -21/+23 | |
| 2022-03-03 | Remove unnecessary #![feature]s from doctest. | Mara Bos | -2/+0 | |
| 2022-03-03 | Rename JoinHandle::is_running to is_finished and update docs. | Mara Bos | -4/+9 | |
| Co-authored-by: Josh Triplett <josh@joshtriplett.org> | ||||
| 2022-01-22 | Add test for thread::Scope invariance. | Mara Bos | -0/+13 | |
| 2022-01-05 | Mention *scoped* thread in panic message. | Mara Bos | -1/+1 | |
| Co-authored-by: Amanieu d'Antras <amanieu@gmail.com> | ||||
| 2022-01-05 | Note the invariance over 'env in Scope<'env>. | Mara Bos | -0/+2 | |
| 2022-01-05 | Fix missing .load() in Scope's Debug impl. | Mara Bos | -1/+1 | |
| 2022-01-05 | Rename n_running_threads to num_running_threads. | Mara Bos | -9/+9 | |
| 2022-01-04 | Fix typo in Scope::spawn docs. | Mara Bos | -1/+1 | |
| Co-authored-by: deltragon <m@dafert.at> | ||||
| 2022-01-04 | Fix typo in is_running() docs. | Mara Bos | -1/+1 | |
| Co-authored-by: Mattias Buelens <649348+MattiasBuelens@users.noreply.github.com> | ||||
| 2022-01-04 | Fix typo in documentation. | Mara Bos | -1/+1 | |
| 2022-01-04 | Use > rather than == for overflow check in scoped threads. | Mara Bos | -1/+1 | |
| Co-authored-by: Jacob Lifshay <programmerjake@gmail.com> | ||||
| 2022-01-04 | Fix variance of thread::Scope. | Mara Bos | -1/+1 | |
| 2022-01-04 | Formatting. | Mara Bos | -1/+3 | |
| 2022-01-04 | Simplify panicking mechanism of thread::scope. | Mara Bos | -23/+17 | |
| It now panic!()s on its own, rather than resume_unwind'ing the panic payload from the thread. Using resume_unwind skips the panic_handler, meaning that the main thread would never have a panic handler run, which can get confusing. | ||||
| 2022-01-04 | Add documentation for scoped threads. | Mara Bos | -11/+175 | |
| 2022-01-04 | Add ScopedJoinHandle::is_running(). | Mara Bos | -1/+10 | |
| 2022-01-04 | Implement RFC 3151: Scoped threads. | Mara Bos | -0/+132 | |
