Tracking Issue for thread spawn hooks
Open
Nobody has claimed this yet.
A-thread
A-thread-locals
C-tracking-issue
F-thread_spawn_hook
T-libs
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Feature gate: #![feature(thread_spawn_hook)]
This is a tracking issue for thread spawn hooks as proposed in https://github.com/rust-lang/rfcs/pull/3642
Public API
// std::thread:
pub fn add_spawn_hook<F, G>(hook: F)
where
F: 'static + Send + Sync + Fn(&Thread) -> G,
G: 'static + Send + FnOnce();
impl Builder {
pub fn no_hooks(mut self) -> Builder;
}
Steps / History
- RFC: https://github.com/rust-lang/rfcs/pull/3642
- Implementation: https://github.com/rust-lang/rust/pull/125405
- Final comment period (FCP)
- Stabilization PR
Unresolved Questions
- Should the return value of the hook be an Option, for when the hook does not require any code to be run in the child?
- Should the hook be able to access/configure more information about the child thread? E.g. set its stack size.
- What should we do when threads are spawned after TLS destruction? (E.g. in an atexit() handler.) Panic? (https://github.com/rust-lang/rust/issues/138696) Or skip them? (https://github.com/rust-lang/rust/pull/138702)
- Giving the hook access to
&Threadbefore the thread has finished initializing means it can't observe the thread ID in most cases. Is that the right behavior?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading RFC 3642 and the implementation referenced in PR 125405, then review the unchecked FCP and stabilization steps. The unresolved questions about hook return values, child-thread configuration, TLS destruction, and thread IDs must be resolved before the feature can be stabilized.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- operating-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100