Skip to content

Use a different method to avoid thread_local on MacOS#1992

Open
dsnopek wants to merge 1 commit into
godotengine:masterfrom
dsnopek:better-macos-thread-local-hack-maybe
Open

Use a different method to avoid thread_local on MacOS#1992
dsnopek wants to merge 1 commit into
godotengine:masterfrom
dsnopek:better-macos-thread-local-hack-maybe

Conversation

@dsnopek
Copy link
Copy Markdown
Collaborator

@dsnopek dsnopek commented May 29, 2026

On macOS, thread_local storage keeps the library from being unloaded, which breaks hot-reload.

So, we've got some messy code that avoids thread_local, but we broke it at some point (per #1990)

This PR takes an alternative solution to the problem, which should be more efficient, and is definitely less messy.

Marking as DRAFT for now, because I still need to actually test it with hot-reload on macOS :-)

Fixes #1990

@dsnopek dsnopek added this to the 10.x milestone May 29, 2026
@dsnopek dsnopek requested a review from a team as a code owner May 29, 2026 23:12
@dsnopek dsnopek added the bug This has been identified as a bug label May 29, 2026
@dsnopek dsnopek changed the title [DRAFT] Use a different method to avoid thread_local on MacOS Use a different method to avoid thread_local on MacOS May 30, 2026
@dsnopek
Copy link
Copy Markdown
Collaborator Author

dsnopek commented May 30, 2026

I just tested this with hot-reload on MacOS, and it worked! Taking out of DRAFT

@Bromeon
Copy link
Copy Markdown
Contributor

Bromeon commented Jun 1, 2026

Note that hot-reloading might again break if the user uses thread_local, either in their own code or through a third-party library. It might be worth documenting this somewhere 🤔

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

Labels

bug This has been identified as a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Off-main-thread instantiation crash on macOS hot-reload builds: _create_instance_func skips _constructing_mutex (unguarded write + unbalanced unlock)

2 participants