Skip to content

Tracking Issue for thread spawn hooks #132951

Description

@m-ou-se

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.
  • What should we do when threads are spawned after TLS destruction? (E.g. in an atexit() handler.) Panic? (std::thread::spawn: thread-local storage panics #138696) Or skip them? (Allow spawning threads after TLS destruction #138702)
  • Giving the hook access to &Thread before the thread has finished initializing means it can't observe the thread ID in most cases. Is that the right behavior?

No activity

Activity on this issue will appear here.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-threadArea: `std::thread`A-thread-localsArea: Thread local storage (TLS)C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCF-thread_spawn_hook`#![feature(thread_spawn_hook)]`T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions