public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
From: "John E. Bossom" <drifting@pioneerwireless.ca>
To: pthreads-win32@sourceware.org
Subject: Re: Static Library Initialization (again?)
Date: Fri, 22 May 2009 02:36:00 -0000	[thread overview]
Message-ID: <20090521223556.den4t7suoccoskc0@webmail.pioneerwireless.ca> (raw)
In-Reply-To: <f460258d0905211708t6e995ffj7aa422078efb1bb0@mail.gmail.com>

>> 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."

There are two ways you can use a "dynamic library" (i.e. DLL)...
Statically link against it's implib and let the loader load it's DLL,
or programmatically by name.
This has nothing to do with an actual "static library" which is what this
topic is about.

Second, please beware that simply taking solutions from other open  
source components has the potential to taint the intellectual property  
rights of this open source component. open source doesn't mean free to  
copy... both Google and Boost are released under license and use of  
their code is subject to their respective license terms.
pthreads-win32 had chosen to release under the LGPL in order to permit  
use by commercial software in addition to open source projects.  
However, commercial companies can come under fire for using open  
source components with questionable lineage. Some commercial companies  
will not touch an open source component if the maintainer does not  
maintain a list of all contributors and can prove the code base is not  
tainted.

Respectfully,

John E. Bossom



Quoting Ramiro Polla <ramiro.polla@gmail.com>:

> Hi,
>
> On Tue, Jun 17, 2008 at 8:27 PM, Brian Cole <coleb2@gmail.com> 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.
>> <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
>> (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?
>
> I attached an ugly but working patch for this. I haven't tested
> building pthreads with MSVC but the initialization code worked on a
> standalone test app.
>
> I added a new make clean GC-autostatic to build the library.
>
> make clean GC-static tests pass. I also tested a bit with FFmpeg (but
> not extensively).
>
> I'm sure it can be dramatically improved (comments, documentation,
> stress test, etc), but as a start it's good enough.
>
> Ramiro Polla
>


  reply	other threads:[~2009-05-22  2:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-17 23:28 Brian Cole
2008-06-18  1:25 ` Ross Johnson
2008-06-18 14:09 ` John E. Bossom
2009-05-22  0:08 ` Ramiro Polla
2009-05-22  2:36   ` John E. Bossom [this message]
2009-06-07 23:39   ` Ramiro Polla

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090521223556.den4t7suoccoskc0@webmail.pioneerwireless.ca \
    --to=drifting@pioneerwireless.ca \
    --cc=pthreads-win32@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).