[Thread] Solution to conflict with MFC?

Hello, I know this has been asked before, but I could not find a good solution. I'm experiencing problems with an application using both MFC and Boost.Thread. Specifically the assertion ASSERT(AfxGetModuleState() != AfxGetAppModuleState()); in AfxCoreInitModule() fails. I link Boost.Thread statically into a DLL in my project. From previous posts to this list and elsewhere, e.g. http://lists.boost.org/boost-users/2009/04/46929.php, I see that the issue is caused by setting _pRawDllMain in tss_pe.cpp. Commenting this line does "solve" the problem, but I would rather not have to hack the Boost source code this way. It seems there is a patch somewhere for this problem (referred to in http://lists.boost.org/boost-users/2009/04/47015.php), but it appears it never made it into the source. Is there any chance of this issue being solved in a better way? Best regards, Christian Larsen

Christian Larsen
Hello,
I know this has been asked before, but I could not find a good solution. I'm experiencing problems with an application using both MFC and Boost.Thread. Specifically the assertion
ASSERT(AfxGetModuleState() != AfxGetAppModuleState());
in AfxCoreInitModule() fails. I link Boost.Thread statically into a DLL in my project.
From previous posts to this list and elsewhere, e.g. http://lists.boost.org/boost-users/2009/04/46929.php, I see that the issue is caused by setting _pRawDllMain in tss_pe.cpp. Commenting this line does "solve" the problem, but I would rather not have to hack the Boost source code this way.
It seems there is a patch somewhere for this problem (referred to in http://lists.boost.org/boost-users/2009/04/47015.php), but it appears it never made it into the source. Is there any chance of this issue being solved in a better way?
Best regards, Christian Larsen
I do not understand the problem nor the given solution completely, but we have no trouble using Boost.Threads within a MFC application. However MFC can only be used within its own threads, so as long as you don't call MFC from your Boost threads there shouldn't be a problem. Those module state asserts are often related to that or using MFC extension DLL's from a non MFC environment. Don't know if this helps u though.

If you are linking boost thread statically, are you also linking MFC and the
C runtime statically?
2011/4/26 Christian Larsen
Hello,
I know this has been asked before, but I could not find a good solution. I'm experiencing problems with an application using both MFC and Boost.Thread. Specifically the assertion
ASSERT(AfxGetModuleState() != AfxGetAppModuleState());
in AfxCoreInitModule() fails. I link Boost.Thread statically into a DLL in my project.
From previous posts to this list and elsewhere, e.g. http://lists.boost.org/boost-users/2009/04/46929.php, I see that the issue is caused by setting _pRawDllMain in tss_pe.cpp. Commenting this line does "solve" the problem, but I would rather not have to hack the Boost source code this way.
It seems there is a patch somewhere for this problem (referred to in http://lists.boost.org/boost-users/2009/04/47015.php), but it appears it never made it into the source. Is there any chance of this issue being solved in a better way?
Best regards, Christian Larsen _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Den 27-04-2011 08:18, Daniel Bradburn skrev:
If you are linking boost thread statically, are you also linking MFC and the C runtime statically?
No, I link dynamically to MFC and the C runtime. I use Visual Studio 2008 with SP1, and Boost version 1.45.0 (but tss_pe.cpp has not changed in 1.46.1 it appears). Best regards, Christian
2011/4/26 Christian Larsen
mailto:contact@dword.dk> Hello,
I know this has been asked before, but I could not find a good solution. I'm experiencing problems with an application using both MFC and Boost.Thread. Specifically the assertion
ASSERT(AfxGetModuleState() != AfxGetAppModuleState());
in AfxCoreInitModule() fails. I link Boost.Thread statically into a DLL in my project.
>From previous posts to this list and elsewhere, e.g. http://lists.boost.org/boost-users/2009/04/46929.php, I see that the issue is caused by setting _pRawDllMain in tss_pe.cpp. Commenting this line does "solve" the problem, but I would rather not have to hack the Boost source code this way.
It seems there is a patch somewhere for this problem (referred to in http://lists.boost.org/boost-users/2009/04/47015.php), but it appears it never made it into the source. Is there any chance of this issue being solved in a better way?
Best regards, Christian Larsen _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org mailto:Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

I'm not sure how restrictive this would be for you but perhaps you could try
statically linking the runtime and mfc libraries rather than dynamically
linking them?
2011/4/27 Christian Larsen
Den 27-04-2011 08:18, Daniel Bradburn skrev:
If you are linking boost thread statically, are you also linking MFC
and the C runtime statically?
No, I link dynamically to MFC and the C runtime. I use Visual Studio 2008 with SP1, and Boost version 1.45.0 (but tss_pe.cpp has not changed in 1.46.1 it appears).
Best regards, Christian
2011/4/26 Christian Larsen
mailto:contact@dword.dk> Hello,
I know this has been asked before, but I could not find a good solution. I'm experiencing problems with an application using both MFC and Boost.Thread. Specifically the assertion
ASSERT(AfxGetModuleState() != AfxGetAppModuleState());
in AfxCoreInitModule() fails. I link Boost.Thread statically into a DLL in my project.
From previous posts to this list and elsewhere, e.g. http://lists.boost.org/boost-users/2009/04/46929.php, I see that the issue is caused by setting _pRawDllMain in tss_pe.cpp. Commenting this line does "solve" the problem, but I would rather not have to hack the Boost source code this way.
It seems there is a patch somewhere for this problem (referred to in http://lists.boost.org/boost-users/2009/04/47015.php), but it appears it never made it into the source. Is there any chance of this issue being solved in a better way?
Best regards, Christian Larsen _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org mailto:Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Daniel Bradburn
I'm not sure how restrictive this would be for you but perhaps you could try statically linking the runtime and mfc libraries rather than dynamically linking them?
I would suggest that the reverse is preferable: dynamically link the boost.thread library. If you must statically link boost.thread, it might be worth trying putting namespace boost { void tss_cleanup_implemented() {} } in your DLL's code. This should avoid linking in the problematic part of the boost library (though I haven't tried it). You will then need to ensure that every thread that uses boost.thread facilities (especially boost::thread_specific_ptr) and is not started with boost::thread calls boost::on_thread_exit() when it exits. 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
participants (4)
-
Anthony Williams
-
Christian Larsen
-
Daniel Bradburn
-
gast128