Hello Kai, On 22/12/13 05:13 AM, Kai Tietz wrote: > Hello Daniel, > > 2013/12/21 Daniel Villeneuve <[email protected]>: >> Hi, >> >> I have a DLL library which declares an "extern __thread int iTlsExtern" >> variable, which I can access from the library and from a program. >> >> However, modifications made from the library to iTlsExtern are not >> seen from the program. >> >> This seems to come from the fact that the address of the variable >> from the library is different from the address from the program. >> > The issue here is that you try to mix two concepts here. A > thread-local variable can't be exported by dll-export, due its address > is mutable for each thread. So it is invalid trying to dllexport such > a variable.
Yes, thread-local variables need to be allocated anew for each thread. However, in my code, there is only a single thread and I would have expected that there would be a single instance of the thread-local variable that would be allocated at runtime and shared by all components of the program. Is the dynamic library vs extern thread-local limitation you bring above specific to Mingw-w64's implementation? or applicable to Windows in general? Using dynamic libraries with extern thread-local variables works as I expect on Linux and Solaris, but this might be an OS-specific property rather than a general standard requirement. > > A valid way of exporting a TLS-variable would be by using a > helper-function, which returns the address of the TLS-variable for the > calling thread. Indeed, this is a working alternative. > > Regards, > Kai > Regards, -- Daniel ------------------------------------------------------------------------------ Rapidly troubleshoot problems before they affect your business. Most IT organizations don't have a clear picture of how application performance affects their revenue. With AppDynamics, you get 100% visibility into your Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro! http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
