Skip to content
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

std: Audit std::thread implementations #24447

Merged
merged 1 commit into from Apr 22, 2015

Conversation

alexcrichton
Copy link
Member

Much of this code hasn't been updated in quite some time and this commit does a
small audit of the functionality:

  • Implementation functions now centralize all functionality on a locally defined
    Thread type.
  • The detach method has been removed in favor of a Drop implementation. This
    notably fixes leaking thread handles on Windows.
  • The Thread structure is now appropriately annotated with Send and Sync
    automatically on Windows and in a custom fashion on Unix.
  • The unsafety of creating a thread has been pushed out to the right boundaries
    now.

Closes #24442

@alexcrichton
Copy link
Member Author

r? @aturon

@rust-highfive rust-highfive assigned aturon and unassigned huonw Apr 15, 2015
@rust-highfive
Copy link
Collaborator

r? @huonw

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

@bors
Copy link
Contributor

bors commented Apr 15, 2015

☔ The latest upstream changes (presumably #24426) made this pull request unmergeable. Please resolve the merge conflicts.

@bors
Copy link
Contributor

bors commented Apr 22, 2015

☔ The latest upstream changes (presumably #24674) made this pull request unmergeable. Please resolve the merge conflicts.


unsafe impl<T:Send> Send for Packet<T> {}
unsafe impl<T> Sync for Packet<T> {}
type Packet<T> = Arc<Mutex<Option<Result<T>>>>;
Copy link
Member

Choose a reason for hiding this comment

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

Why introduce a mutex? The use of join should already guarantee sufficient synchronization.

Copy link
Member Author

Choose a reason for hiding this comment

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

This helped avoid a number of unsafe impl blocks as well as removing a bit of unsafe code. I definitely agree that it was properly synchronized before, I was just hoping to cut down on the amount of unsafe here. I'll see if I can't finesse a nicer solution to this though.

Copy link
Member

Choose a reason for hiding this comment

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

OK. Not a huge deal, the extra call into system APIs would probably never show up on a profile.

@aturon
Copy link
Member

aturon commented Apr 22, 2015

This looks good to me, though I am curious about the introduction of a Mutex in the Packet type.

Much of this code hasn't been updated in quite some time and this commit does a
small audit of the functionality:

* Implementation functions now centralize all functionality on a locally defined
  `Thread` type.
* The `detach` method has been removed in favor of a `Drop` implementation. This
  notably fixes leaking thread handles on Windows.
* The `Thread` structure is now appropriately annotated with `Send` and `Sync`
  automatically on Windows and in a custom fashion on Unix.
* The unsafety of creating a thread has been pushed out to the right boundaries
  now.

Closes rust-lang#24442
@alexcrichton
Copy link
Member Author

@bors: r=aturon

@bors
Copy link
Contributor

bors commented Apr 22, 2015

📌 Commit 2e11009 has been approved by aturon

@bors
Copy link
Contributor

bors commented Apr 22, 2015

⌛ Testing commit 2e11009 with merge 5c96369...

bors added a commit that referenced this pull request Apr 22, 2015
Much of this code hasn't been updated in quite some time and this commit does a
small audit of the functionality:

* Implementation functions now centralize all functionality on a locally defined
  `Thread` type.
* The `detach` method has been removed in favor of a `Drop` implementation. This
  notably fixes leaking thread handles on Windows.
* The `Thread` structure is now appropriately annotated with `Send` and `Sync`
  automatically on Windows and in a custom fashion on Unix.
* The unsafety of creating a thread has been pushed out to the right boundaries
  now.

Closes #24442
@bors bors merged commit 2e11009 into rust-lang:master Apr 22, 2015
@alexcrichton alexcrichton deleted the audit-thread branch April 30, 2015 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

compiles on linux but not windows
5 participants