-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Expose process windows_process_extensions_main_thread_handle on Windows #96725
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
(rust-highfive has picked a reviewer for you, use r? to override) |
Why not expose the thread handle instead of the thread id? |
Agreed, although are there any downsides is holding a thread handle open? |
I didn't realize there was precedent for exposing the process handle directly, just saw the id() method and missed |
Btw, there are tests that run processes in |
Added a test |
Ok, so my concern was that keeping the thread handle open is an insta-stable change so I wanted to be sure this wouldn't cause breakage. However, I think I've satisfied myself that closing it at the same time as the process handle won't be an issue for existing code. The worst that can happen is some kernel data structures are needlessly kept around in the event that a child process exits its main thread but the process continues running other threads (which would itself be a very unusual situation). My only other concern is that perhaps new APIs should be making use of the (currently unstable) |
I'll ask @rust-lang/libs-api if they're ok with this. |
Can this even happen? As far as I can tell, when the main thread exits Windows will exit the process anyway. |
Might be good to do that right away. Then we get some usage of BorrowedHandle before stabilizing it, to see if it works well. :) |
It's possible! In Win32, a process only exits when all threads have exited or ExitProcess is called (which terminates all other threads), |
Good point. @nico-abram could you update the implementation to return |
adaa03b
to
b5789a0
Compare
This comment has been minimized.
This comment has been minimized.
Rebased on master and changed the API to use BorrowedHandle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Just a few small points.
This comment has been minimized.
This comment has been minimized.
Great, thanks! If you could squish the commits then I think this will be ready to be merged. |
ecb9dff
to
65b9586
Compare
Squished |
@bors r+ |
📌 Commit 5368ea7 has been approved by |
@bors rollup |
Rollup of 6 pull requests Successful merges: - rust-lang#96717 (Handle mismatched generic param kinds in trait impls betterly) - rust-lang#96725 (Expose process windows_process_extensions_main_thread_handle on Windows) - rust-lang#96849 (Move some tests to more reasonable places) - rust-lang#96861 (Use Rust 2021 prelude in std itself.) - rust-lang#96879 (rustdoc: search result ranking fix) - rust-lang#96882 (Don't subst an AdtDef with its own substs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
I did not find any tests in https://github.com/rust-lang/rust/blob/7d3e03666a93bd2b0f78b3933f9305832af771a5/library/std/src/sys/windows/process/tests.rs that actually launch processes, so I haven't added tests for this.I ran the following locally, to check that it works as expected:Without the feature attribute it wouldn't compile, and commenting the
ResumeThread
line makes it hang forever, showing that it works.Tracking issue #96723