Skip to content

Conversation

@ohadravid
Copy link

Follow to rust-lang/rust#148799, specifically @alexcrichton's comment.

Summary: rust-lang/rust#148799 switches the way destructors for thread locals are scheduled on Windows, and will now use Fiber Local Storage (FlsAlloc accepts a callback that is called on fiber/thread/process exit).

Because wasmtime uses Fibers on Windows to support async functions, it now need to make sure that this hook is registered before Fibers are used.

To do that, we create an additional TLS variable with a Drop impl, and use it just before calling ConvertThreadToFiber. Because ConvertFiberToThread is already called before exiting, this guarantees that the hook will both be registered correctly, and invoked when the thread exits.

If a fiber does exit abnormally, it's possible that ConvertFiberToThread won't be called, in which case thread locals with Drop impls will be leaked.

@alexcrichton - let me know if you want me to add a resume_separate_thread-like test that uses thread locals + a "native" os thread (== one that isn't initialized with the Rust runtime).

@ohadravid ohadravid requested a review from a team as a code owner January 24, 2026 18:31
@ohadravid ohadravid requested review from pchickey and removed request for a team January 24, 2026 18:31
@alexcrichton
Copy link
Member

Thanks for this! If you've got a test that'd be awesome to add, but no need to go out of your way for that. You can feel free to add it to this crate itself or in the top level tests/* as appropriate

@alexcrichton alexcrichton requested review from alexcrichton and removed request for pchickey January 24, 2026 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants