[Thread] Using thread accross libraries

Hi all,
first, thanks for this great library.
I'm using Boost::thread and experiencing a problem when trying to interrupt
thread executed in a dynamic library (DLL, under Windows).
I reproduced it in a minimal example, that I join to this post (I don't
know if attachment is authorized so I also put it on my
GDrivehttps://drive.google.com/file/d/0B3dXqBwTbfcAQ1E0MDRfU0hxNVE/edit?usp=sharin...,
and copy the code at the end of this mail).
In this code, I start a thread in the main, calling a function "doWork" of
a plugin, dynamically loaded.
The doWork just do some sleep and wait for boost::thread_interrupted
exception.
The problem is that the exception is never received when the main call
interrupt on the thread.
If the doWork code is in the main application, all works well.
Trying to debug into Boost, I'm seeing that in the interruptible_wait
function, the test "if(detail::get_current_thread_data() &&
detail::get_current_thread_data()->interruption_enabled)" doesn't give the
same result if code is in DLL (test result is false) or in the main (true).
What is the reason of this behaviour ?
Thanks for your help,
Sébastien Gallou
Here is the code :
*TestBoostThread.cpp :*
IPlugin* Plugin;
void doWork(){
try
{
Plugin->doWork();
}
catch (boost::thread_interrupted&)
{
// End-of-thread exception was not catch by plugin,
// it's a developer's error, we have to report it
std::cout << "Plugin didn't catch boost::thread_interrupted.";
}}
int main(int argc, char* argv[]){
HMODULE libraryHandle = LoadLibrary(L"Dll.dll");
boost::function

2013/11/26 Sébastien Gallou
Trying to debug into Boost, I'm seeing that in the interruptible_wait function, the test "if(detail::get_current_thread_data() && detail::get_current_thread_data()->interruption_enabled)" doesn't give the same result if code is in DLL (test result is false) or in the main (true).
Looks like TestBoostThread.cpp and Dll.cpp are compiled with different runtime libraries. Make sure that in properties of each project values of "Configuration Properties"->"C/C++"->"Code Generation"->"Runtime library" are equal. Also make sure that they are set to use DLLs ("Multi-threaded Debug DLL" or "Multi-threaded DLL"). Without that you'll be getting really strange errors all around your binaries, because memory allocated in one binary/dll won't be correctly handled in another dll/binary. -- Best regards, Antony Polukhin
participants (2)
-
Antony Polukhin
-
Sébastien Gallou