This is the mail archive of the
mailing list for the pthreas-win32 project.
Re: Static Library Initialization (again?)
- From: Ross Johnson <Ross dot Johnson at homemail dot com dot au>
- To: Brian Cole <coleb2 at gmail dot com>
- Cc: pthreads-win32 at sourceware dot org
- Date: Wed, 18 Jun 2008 11:24:38 +1000
- Subject: Re: Static Library Initialization (again?)
- References: <email@example.com>
Brian Cole wrote:
A patch based on the Boost solution would be very welcome. It looks to
me like both Google and Boost are using the same technique but the Boost
version appears to include a version for Mingw32.
It looks like I'm running into the same problem as others. I need to
distribute a static library with pthreads-win32 included without
requiring end-users of our library to call any pthreads-win32 specific
attach or detach code. Based on previous posts to the mailing list it
looks like the boost library has dealt with this before:
I also found this bit of code inside the Google performance tools:
// This tells the linker to run these functions.
#pragma data_seg(push, old_seg)
static void (NTAPI *p_thread_callback)(HINSTANCE h, DWORD dwReason, PVOID pv)
static int (*p_process_term)(void) = on_process_term;
#pragma data_seg(pop, old_seg)
#else // #ifdef _MSC_VER [probably msys/mingw]
// We have to try the DllMain solution here, because we can't use the
// msvc-specific pragmas.
<snipped for brevity>
#endif // #ifdef _MSC_VER
Any reason pthreads-win32 can't use these same mechanisms to initialize itself?
Why can't DllMain be used for this? MSDN seems to imply that DllMain
is called for static libraries
"The lpReserved parameter indicates whether the DLL is being loaded
statically or dynamically."
I just looked through boost and found their implementation
(boost-trunk/libs/thread/src/win32/tss_pe.cpp). Any objection to me
creating a patch based on this code for pthreads-win32?
I'm not familiar with this enough to tell - does this solution work for
dynamic loading as well, or just static? I ask because there are a
couple of calls in DllMain that are forbidden according to the Microsoft
doco, such as calling LoadLibrary, but work anyway.