Open collinoc opened 6 months ago
Trimmed down the examples and explanation for clarity. Also included Rust version info.
You are aware that what you are doing here is highly platform dependant. For example musl-libc doesnt even support library unloading. Its a noop there.
Glibc to my knowlege has a refcounter and does actually to some extend unload librarys.
I do not know with which criteria windows decides to remove a dll from the process address space after you call CloseHandle on the libraries handle.
I personally try to never unload shared objects/libraries as most libs do not even implement unloading properly. You are probably observing just this in your example.
I'm running into an issue with static thread local storage that contains a heap-allocated object when loading a library.
Given a simple library:
and a main program that will repeatedly load said library:
The issue I'm seeing: Calling
lib_func
from the main loop initially printsCell: 1
as expected. If you change the value to say,2
, within the RefCell inlib_func
and recompile, the main loop will still repeatedly printCell: 1
.If you replace the
RefCell
with a plainCell
, then once changing the value to2
and recompiling, it would start printingCell: 2
, as I would expect.The
Box<u8>
within theRefCell
can be replaced with any other heap-allocated object such as aString
orVec
to see the same unexpected behavior.Full Example
Rust info: