ohadravid opened PR #12426 from ohadravid:windows-fls-thread-local-guard to bytecodealliance:main:
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->Follow to https://github.com/rust-lang/rust/pull/148799, specifically @alexcrichton's comment.
Summary: https://github.com/rust-lang/rust/pull/148799 switches the way destructors for thread locals are scheduled on Windows, and will now use Fiber Local Storage (
FlsAllocaccepts a callback that is called on fiber/thread/process exit).Because
wasmtimeuses 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
Dropimpl, and use it just before callingConvertThreadToFiber. BecauseConvertFiberToThreadis 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
ConvertFiberToThreadwon't be called, in which case thread locals withDropimpls 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 requested wasmtime-core-reviewers for a review on PR #12426.
ohadravid requested pchickey for a review on PR #12426.
alexcrichton commented on PR #12426:
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 unassigned pchickey from PR #12426 Added a thread_local guard to trigger dtor hook before fibers are used.
alexcrichton requested alexcrichton for a review on PR #12426.
ohadravid updated PR #12426.
alexcrichton submitted PR review.
alexcrichton commented on PR #12426:
Thanks so much again for this!
alexcrichton added PR #12426 Added a thread_local guard to trigger dtor hook before fibers are used to the merge queue.
alexcrichton merged PR #12426.
alexcrichton removed PR #12426 Added a thread_local guard to trigger dtor hook before fibers are used from the merge queue.
Last updated: Jan 29 2026 at 13:25 UTC