-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revise std::thread #22435
Revise std::thread #22435
Conversation
This is WIP because I haven't yet moved the rest of the codebase off of now-deprecated functions. I wanted to get feedback on the direction of the API first. |
👍 for me! |
Looks great! |
👍 |
1 similar comment
👍 |
/// to recover from such errors. | ||
#[unstable(feature = "thread", reason = "recently moved")] | ||
pub fn scoped<'a, T, F>(f: F) -> JoinGuard<'a, T> where | ||
T: Send + 'a, F: FnOnce() -> T, F: Send + 'a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this 'a
bound on T
required? I would expect that the compiler would already ensure that T
couldn't refer to anything inside the local environment of F
. As in, I expect 'a
to only be relevant to the lifetime of the closure and that would in turn imply that it bounds T
.
This looks great to me, r=me with a small nits and doc tests passing. |
I also talked with @aturon today and I would be comfortable marking these functions |
This commit makes several changes to `std::thread` in preparation for final stabilization: * It removes the ability to handle panics from `scoped` children; see rust-lang#20807 for discussion * It adds a `JoinHandle` structure, now returned from `spawn`, which makes it possible to join on children that do not share data from their parent's stack. The child is automatically detached when the handle is dropped, and the handle cannot be copied due to Posix semantics. * It moves all static methods from `std::thread::Thread` to free functions in `std::thread`. This was done in part because, due to the above changes, there are effectively no direct `Thread` constructors, and the static methods have tended to feel a bit awkward. * Adds an `io::Result` around the `Builder` methods `scoped` and `spawn`, making it possible to handle OS errors when creating threads. The convenience free functions entail an unwrap. * Stabilizes the entire module. Despite the fact that the API is changing somewhat here, this is part of a long period of baking and the changes are addressing all known issues prior to alpha2. If absolutely necessary, further breaking changes can be made prior to beta. Closes rust-lang#20807 [breaking-change]
d3fa01a
to
891aeaa
Compare
891aeaa
to
d0de2b4
Compare
@alexcrichton OK, I've pushed an update including a fallout commit. It hasn't gotten through tests yet, but I think any trouble there should be minor (if you want to stick it in a rollup). I'll keep pushing through the compilation meanwhile. |
/// handle: the ability to join a child thread is a uniquely-owned | ||
/// permission. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub struct JoinHandle(JoinInner<()>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a non-tuple struct per #22045?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The component is private, so I don't think there's any problem here.
Conflicts: src/test/bench/rt-messaging-ping-pong.rs src/test/bench/rt-parfib.rs src/test/bench/task-perf-spawnalot.rs
Since |
While we're poking at the I've done something similar with r2d2's |
This commit makes several changes to
std::thread
in preparation forfinal stabilization:
scoped
children; seeJoinGuard::join returning an Err is **really** unsafe #20807 for discussion
JoinHandle
structure, now returned fromspawn
, whichmakes it possible to join on children that do not share data from
their parent's stack. The child is automatically detached when the
handle is dropped, and the handle cannot be copied due to Posix
semantics.
std::thread::Thread
to freefunctions in
std::thread
. This was done in part because, due to theabove changes, there are effectively no direct
Thread
constructors,and the static methods have tended to feel a bit awkward.
io::Result
around theBuilder
methodsscoped
andspawn
, making it possible to handle OS errors when creatingthreads. The convenience free functions entail an unwrap.
changing somewhat here, this is part of a long period of baking and
the changes are addressing all known issues prior to alpha2. If
absolutely necessary, further breaking changes can be made prior to beta.
Closes #20807
[breaking-change]
r? @alexcrichton