From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25278 invoked by alias); 18 Jun 2008 01:25:11 -0000 Received: (qmail 25225 invoked by uid 22791); 18 Jun 2008 01:25:11 -0000 X-Spam-Check-By: sourceware.org Received: from flexo.grapevine.net.au (HELO flexo.grapevine.net.au) (203.129.32.140) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 18 Jun 2008 01:24:44 +0000 Received: from localhost (localhost [127.0.0.1]) by flexo.grapevine.net.au (Postfix) with ESMTP id 31287580917; Wed, 18 Jun 2008 11:24:40 +1000 (EST) Received: from flexo.grapevine.net.au ([127.0.0.1]) by localhost (flexo.grapevine.net.au [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VmambTT87RtG; Wed, 18 Jun 2008 11:24:40 +1000 (EST) Received: from localhost.localdomain (ppp-187.40.129.203.grapevine.net.au [203.129.40.187]) by flexo.grapevine.net.au (Postfix) with ESMTP id A0CF85808FE; Wed, 18 Jun 2008 11:24:39 +1000 (EST) Message-ID: <485863D6.3000203@homemail.com.au> Date: Wed, 18 Jun 2008 01:25:00 -0000 From: Ross Johnson User-Agent: Thunderbird 2.0.0.14 (X11/20080501) MIME-Version: 1.0 To: Brian Cole CC: pthreads-win32@sourceware.org Subject: Re: Static Library Initialization (again?) References: <54b165660806171627i489ec78at85e8576762fe97af@mail.gmail.com> In-Reply-To: <54b165660806171627i489ec78at85e8576762fe97af@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact pthreads-win32-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: pthreads-win32-owner@sourceware.org X-SW-Source: 2008/txt/msg00029.txt.bz2 Brian Cole wrote: > 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: > http://sourceware.org/ml/pthreads-win32/2008/msg00022.html > > I also found this bit of code inside the Google performance tools: > #ifdef _MSC_VER > > // This tells the linker to run these functions. > #pragma data_seg(push, old_seg) > #pragma data_seg(".CRT$XLB") > static void (NTAPI *p_thread_callback)(HINSTANCE h, DWORD dwReason, PVOID pv) > = on_tls_callback; > #pragma data_seg(".CRT$XTU") > 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. > > > #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 > (http://msdn.microsoft.com/en-us/library/ms682583.aspx): > "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? > 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. 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. > -Brian >