-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Make it possible to compare threads #1435
Comments
Should be pretty simple - |
There has been a bunch of attempts to implement this already: Also see: |
@alexcrichton your comment in one of the implementation attempts suggests that |
Threads themselves are somewhat more opaque and it's in general just a little more flexible to deal with ids instead of threads themselves. We could also lower the |
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
|
Objects of type
Thread
can't be compared. There's no way to know if you are still in the same thread as you were before.I don't know if this should just be an implementation of
Eq
onThread
, or if a newThreadId
type would need to be created.The text was updated successfully, but these errors were encountered: