Skip to content

Stabilize windows_process_extensions_main_thread_handle - #160108

Open
ChayimFriedman2 wants to merge 1 commit into
rust-lang:mainfrom
ChayimFriedman2:stabilize-main-thread-windows
Open

Stabilize windows_process_extensions_main_thread_handle#160108
ChayimFriedman2 wants to merge 1 commit into
rust-lang:mainfrom
ChayimFriedman2:stabilize-main-thread-windows

Conversation

@ChayimFriedman2

Copy link
Copy Markdown
Contributor

I propose we stabilize the library feature windows_process_extensions_main_thread_handle (tracking issue #96723).

Stabilization Report

Implementation History

This feature was added in #96725, and not changed since.

API Summary

// std::os::windows::process

pub trait ChildExt: Sealed {
    fn main_thread_handle(&self) -> BorrowedHandle<'_>;
}

This method gives access to the handle to the main thread of a spawned child process on Windows. It is not possible to get after spawning using documented APIs, and it's useful for example for resuming a process that started as suspended (while it's possible to enumerate all threads and resume them all, that's slower and more complicated).

Experience Report

My personal reason for this is wanting to use it for this case exactly (resuming a suspended process) in rust-analyzer, see rust-lang/rust-analyzer#22763 (comment). Other people seem to want this for the same reason as well (for example in the tracking issue). Searching GitHub for .main_thread_handle() gives 269 results. Some are for resuming processes, but there are also others - for example, injecting a DLL. I even found a project that gates using this method behind a feature, and if it's not set, uses an undocumented Windows API instead.

Unresolved Questions

There are two unresolved questions:

  • The naming - should it be the "main thread" or the "primary thread". Microsoft's documentation refers to it as the "primary thread", but our own docs mention "main thread" (https://doc.rust-lang.org/std/thread/index.html), as stated in Tracking Issue for windows_process_extensions_main_thread_handle #96723 (comment). I left it as "main thread".
  • Should it return Option<BorrowedHandle<'_>>? This will enable conversion from a handle to std::process::Child (such conversion is not supported currently). Such conversion is not supported for any OS currently though, and making this function returning Option will complicate code using it, so I chose to not do that.

r? libs-api

@rustbot rustbot added O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 28, 2026
@ChayimFriedman2 ChayimFriedman2 added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. labels Jul 28, 2026
@rust-log-analyzer

This comment has been minimized.

Giving access to `std::os::windows::process::ChildExt::main_thread_handle()`.
@ChayimFriedman2
ChayimFriedman2 force-pushed the stabilize-main-thread-windows branch from 643919c to 18f6cad Compare July 28, 2026 23:45
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job tidy failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
fmt: checked 7059 files
tidy check
tidy [rustdoc_json (src)]: `rustdoc-json-types` modified, checking format version
tidy: Skipping binary file check, read-only filesystem
tidy [features]: /checkout/library/std/src/os/windows/process.rs:438: malformed stability attribute: can't parse `since` key
tidy [features]: /checkout/library/std/src/os/windows/process.rs:441: malformed stability attribute: missing the `since` key
tidy [features]: /checkout/library/std/src/os/windows/process.rs:448: malformed stability attribute: can't parse `since` key
tidy [features]: FAIL
removing old virtual environment
creating virtual environment at '/checkout/obj/build/venv' using 'python3.10' and 'venv'
creating virtual environment at '/checkout/obj/build/venv' using 'python3.10' and 'virtualenv'
Requirement already satisfied: pip in ./build/venv/lib/python3.10/site-packages (26.1.2)
linting python files
---
Running eslint on rustdoc JS files
info: ES-Check: checking 7 files...
info: ✓ ES-Check passed! All files are ES10 compatible.
typechecking javascript files
tidy: The following check failed: features
Command `/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools-bin/rust-tidy --root-path=/checkout --cargo-path=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo --output-dir=/checkout/obj/build --concurrency=4 --npm-path=/node/bin/yarn --ci=true --extra-checks=py,cpp,js,spellcheck` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/tool.rs:1627:23
Executed at: src/bootstrap/src/core/build_steps/test.rs:1682:29

Command has failed. Rerun with -v to see more details.
Bootstrap failed while executing `test src/tools/tidy tidyselftest --extra-checks=py,cpp,js,spellcheck`
Currently active steps:
test::Tidy {  } at src/bootstrap/src/core/build_steps/test.rs:1604
Build completed unsuccessfully in 0:02:38
  local time: Tue Jul 28 23:51:18 UTC 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. 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.

4 participants