-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Implement Eq for Thread #29447
Implement Eq for Thread #29447
Conversation
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
The idea and implementation seem reasonable. |
I would personally prefer an implementation route along the lines #29457, which is to say using the system primitives over our own abstractions, but I believe that today both will always yield the same results. Regardless, though, I'm gonna tag this with T-libs so it comes up during libs triage. Thanks for the PR @remram44! |
Oh wait that doesn't make sense as an implementation strategy, these only contain our own allocations, nevermind! |
The libs team discussed this during triage today and there was quite a bit of discussion and we didn't quite reach a conclusion. Some thoughts we had were:
|
Closing due to inactivity, but feel free to resubmit with the comments on this and #29448 addressed! |
Add ThreadId for comparing threads This adds the capability to store and compare threads with the current calling thread via a new struct, `std::thread::ThreadId`. Addresses the need outlined in issue #21507. This avoids the need to add any special checks to the existing thread structs and does not rely on the system to provide an identifier for a thread, since it seems that this approach is unreliable and undesirable. Instead, this simply uses a lazily-created, thread-local `usize` whose value is copied from a global atomic counter. The code should be simple enough that it should be as much reliable as the `#[thread_local]` attribute it uses (however much that is). `ThreadId`s can be compared directly for equality and have copy semantics. Also see these other attempts: - #29457 - #29448 - #29447 And this in the RFC repo: rust-lang/rfcs#1435
Fixes #21507
This simply compares the Arcs in the Threads since there is one Inner struct per thread.
Will add tests if there is interest in this.