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

Tracking Issue for thread spawn hooks #132951

Open
2 of 4 tasks
m-ou-se opened this issue Nov 12, 2024 · 1 comment
Open
2 of 4 tasks

Tracking Issue for thread spawn hooks #132951

m-ou-se opened this issue Nov 12, 2024 · 1 comment
Labels
A-thread Area: `std::thread` A-thread-locals Area: Thread local storage (TLS) C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC F-thread_spawn_hook `#![feature(thread_spawn_hook)]` T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@m-ou-se
Copy link
Member

m-ou-se commented Nov 12, 2024

Feature gate: #![feature(thread_spawn_hook)]

This is a tracking issue for thread spawn hooks as proposed in rust-lang/rfcs#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

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.
@m-ou-se m-ou-se added A-thread Area: `std::thread` A-thread-locals Area: Thread local storage (TLS) C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Nov 12, 2024
@Erk-
Copy link
Contributor

Erk- commented Nov 22, 2024

Before this is stabilized there should be documentation added about panics in the places where it makes sense which I think would be std::thread::spawn, std::thread::Scope::spawn and std::thread::Builder::{spawn, spawn_scoped}.

I don't think it is appropriate to add it yet since it is a experimental feature still.

@jieyouxu jieyouxu added the F-thread_spawn_hook `#![feature(thread_spawn_hook)]` label Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-thread Area: `std::thread` A-thread-locals Area: Thread local storage (TLS) C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC F-thread_spawn_hook `#![feature(thread_spawn_hook)]` T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants