Stream: git-wasmtime

Topic: wasmtime / PR #12426 Added a thread_local guard to trigge...


view this post on Zulip Wasmtime GitHub notifications bot (Jan 24 2026 at 18:31):

ohadravid opened PR #12426 from ohadravid:windows-fls-thread-local-guard to bytecodealliance:main:

<!--
Please make sure you include the following information:

Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.html

Please 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 (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).

view this post on Zulip Wasmtime GitHub notifications bot (Jan 24 2026 at 18:31):

ohadravid requested wasmtime-core-reviewers for a review on PR #12426.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 24 2026 at 18:31):

ohadravid requested pchickey for a review on PR #12426.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 24 2026 at 23:03):

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

view this post on Zulip Wasmtime GitHub notifications bot (Jan 24 2026 at 23:03):

alexcrichton unassigned pchickey from PR #12426 Added a thread_local guard to trigger dtor hook before fibers are used.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 24 2026 at 23:03):

alexcrichton requested alexcrichton for a review on PR #12426.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 28 2026 at 19:42):

ohadravid updated PR #12426.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 28 2026 at 20:12):

alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 28 2026 at 20:12):

alexcrichton commented on PR #12426:

Thanks so much again for this!

view this post on Zulip Wasmtime GitHub notifications bot (Jan 28 2026 at 20:12):

alexcrichton added PR #12426 Added a thread_local guard to trigger dtor hook before fibers are used to the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 28 2026 at 20:40):

alexcrichton merged PR #12426.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 28 2026 at 20:40):

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