Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/libstd/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,15 @@ impl Thread {
}
}

impl PartialEq<Thread> for Thread {
fn eq(&self, other: &Thread) -> bool {
// Compare the Arcs
(&*self.inner as *const Inner) == (&*other.inner as *const Inner)
}
}

impl Eq for Thread {}

#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Debug for Thread {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down Expand Up @@ -656,6 +665,20 @@ mod tests {
}).unwrap().join().unwrap();
}

#[test]
fn test_thread_eq() {
let (tx, rx) = channel();
let t1 = thread::spawn(move|| {
tx.send(thread::current()).unwrap();
}).thread();
let t2 = rx.recv().unwrap();
let t3 = thread::spawn(move|| {
}).thread();
assert!(t1 == t1);
assert!(t1 == t2);
assert!(t1 != t3);
}

#[test]
fn test_run_basic() {
let (tx, rx) = channel();
Expand Down