Subject: Re: [boost] Fwd: [Thread] Solution to conflict with MFC?
From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2011-04-27 12:21:03
Thorsten Ottosen <thorsten.ottosen_at_[hidden]> writes:
> Den 27-04-2011 17:13, Anthony Williams skrev:
>> Thorsten Ottosen<thorsten.ottosen_at_[hidden]> writes:
>> It is more of a hack than a patch: remove the use of _pRawDllMain from
>> tss_pe.cpp, and add a new object file outside the boost thread library
>> that contains a _pRawDllMain that calls both the MFC and Boost
>> initialization functions. The user must explicitly add that object file
>> to their project.
> Hm. That does sound like a hack. But at least it doesn't require users
> to modify boost source code whenever they upgrade boost.
> 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 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.
-- 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