|
Boost : |
Subject: Re: [boost] Fwd: [Thread] Solution to conflict with MFC?
From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2011-04-28 02:41:32
Thorsten Ottosen <thorsten.ottosen_at_[hidden]> writes:
> Den 27-04-2011 18:21, Anthony Williams skrev:
>> Thorsten Ottosen<thorsten.ottosen_at_[hidden]> writes:
>>
>>> Den 27-04-2011 17:13, Anthony Williams skrev:
>>>> Thorsten Ottosen<thorsten.ottosen_at_[hidden]> writes:
>
>>> Is there any possibility that the initialization of this pointer
>>> in tss_pe.cpp can be made dynamic based on some parameter
>>> passed to the code? It would be really cool if we could just say
>>>
>>> #define BOOST_THREAD_DISABLED_DLL_CALLBACK 1
>>> #include<boost/thread.hpp>
>>>
>>> in the code that needs it. AFAICR, we can have global data in headers
>>> as long as it is inside some template.
>>
>> For the DLL callback to be called automatically, there must be an extern
>> "C" global variable called _pRawDllMain, which must be statically
>> initialized to point to the callback function.
>>
>> I don't see how you could put that in a header without risking >
>> multiple
>> definition errors --- the header that initialized it would have to be
>> included exactly once across the whole project. Failure to include it
>> anywhere would mean that the init function would not be linked.
>
> I searched the source directory to locate this variable. Is
>
> extern BOOL (WINAPI * const _pRawDllMain)(HANDLE, DWORD,LPVOID);
>
> not just a declaration of a variable located somewhere else?
As you've written it, it would be. In the real code there's actually an initializer:
extern BOOL (WINAPI * const _pRawDllMain)(HANDLE, DWORD, LPVOID)=&dll_callback;
which means that it is a const variable with external linkage.
> If so, we only need to put the initialization of this variable
> in a header.
But doing so would yield multiple initialization errors.
>> I haven't tried it, but I think that if the application defines
>> boost::tss_cleanup_implemented() then tss_pe.cpp will not get linked
>> from the library, so the DLL callback will not be linked, and the MFC
>> one should therefore work. Of course, you will then need to ensure that
>> boost::on_thread_exit() is called when every thread exits to avoid
>> leaking memory and/or resources.
>
> yeah, that won't work well. Then it's far better to include a seperate
> .cpp file.
Anyone care to try the attached file?
Anthony
-- Author of C++ Concurrency in Action http://www.stdthread.co.uk/book/ just::thread C++0x thread library http://www.stdthread.co.uk Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk