Handmade Network»Forums
6 posts
thread_local Variables break code reloading?

Hi folks,

I have a code reloading system similar to the one detailed in Day 21 and I've recently been adapting some of my code to use thread_local globals. I was surprised to find that the addition of a thread_local variable is enough to stop the code reloading from working.

In this Video, I start by compiling the program without a thread_local and test the code reloading to see that it works. I then quit the program and recompile with a thread_local to then see that code reloading no longer works (note that a second "TheGlobalInt: ..." line does not appear in the bottom left).

Does anyone have any thoughts as to why this might be? Tested with Apple Clang 14 on macOS 10.12.

Thanks,
Robin

Mārtiņš Možeiko
2443 posts / 2 projects
thread_local Variables break code reloading?

Having such global variable should not change how rest of code works. It should work. You are experiencing some other issue.

6 posts
thread_local Variables break code reloading?
Replying to mmozeiko (#26978)

Seems that dlclose never actually unloads the library image from the address space and just reuses the old version of the library in some cases. Apparantly dlclose implementations are not actually required to unload anything from the address space. Any way around this short of rewriting dlopen/close/sym?