Skip to content

Implement Partial{,Eq} for JoinHandle & os::Thread #29457

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

Closed
wants to merge 1 commit into from

Conversation

nagisa
Copy link
Member

@nagisa nagisa commented Oct 29, 2015

Windows implementation is untested.

Complements the Eq for Thread PR.

@rust-highfive
Copy link
Contributor

r? @aturon

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton
Copy link
Member

While the underlying implementations may be useful, I'm not sure why we'd want to implement PartialEq for JoinHandle? By construction you can never have two that are equal.

@nagisa
Copy link
Member Author

nagisa commented Oct 29, 2015

@alexcrichton putting it into Arc/Rc or similar owning pointer makes it possible to have several pointers to the same JoinGuard, and impl<T> PartialEq<Arc<T>> for Arc<T> where T: PartialEq<T> + ?Sized.

I’d argue it has similar usefulness as implementing Eq on std::thread::Thread.

@@ -106,3 +107,13 @@ impl RawHandle {
Ok(Handle::new(ret))
}
}

impl PartialEq<RawHandle> for RawHandle {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the parameter on PartialEq is defaulted to Self so this and the ones around I believe can be left off.

@alexcrichton
Copy link
Member

Hm I guess so, yeah, makes sense.

I'm gonna tag with T-libs so this comes up during triage, thanks for the PR @nagisa!

@alexcrichton alexcrichton added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Oct 29, 2015
@nagisa
Copy link
Member Author

nagisa commented Nov 1, 2015

CompareObjectHandles is W10+, so can’t be used.

@nagisa nagisa closed this Nov 1, 2015
bors added a commit that referenced this pull request Oct 10, 2016
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants