You are not logged in.
In practice, what does it mean with "do not..."?
Offline
It means "do not access directly this threadvar when used within Delphi packages".
Or it would fail compiling.
This is a limitation of Delphi packages: to properly load and link a package, any threadvar variable should not be accessed directly, but through a function which returns a pointer to the current threadvar.
AFAIK this is because threadvar uses some kind of lookup table (TLS = Thread Local Storage) which changes for each compiled module.
Offline
Please, excuse my newbieness in this respect... Does it mean threadvars inside packages are "safe" if they are declared inside the implementation?
Because all the threadvars in mormot2 are declared inside the implementation, so unless you modify the mormot2 sources, they would be safe
Last edited by Javierus (2024-11-04 16:56:11)
Offline
So we can not compile mORMot2 as-is in a package and use it safely?
Offline
Thank you; it does compile perfectly
I didn't understood you, but finally did
Offline
Threadvar's are created in a special memory area (thread-local storage). At compile time the addresses of that space for a thread created at runtime isn't fix.
Therefore libraries linked at compile time (which packages are) could have an issue with threadvar's. Dynamically loaded libraries are fine, because they will loaded at runtime, when the threads run.
Because of this it doesn't matter whether a threadvar is declared in interface or implementation part.
Offline