I have trouble with a clean up function within a dll.
here is the code that works that do not work inside a dll.
dll code
=============================
void detach_thread(unsigned int * in_current_thread_index)
{
scoped_lock_recursive lock(mutex);
std::cout << "detatching thread in slot " << *in_current_thread_index << std::endl;
delete in_current_thread_index;
}
boost::thread_specific_ptr<unsigned int> current_thread_index(&detach_thread);
BOOL WINAPI DllMain(HINSTANCE hinstDLL, // handle to DLL module
DWORD fdwReason, // reason for calling function
LPVOID lpReserved ) // reserved
{
LPVOID lpvData;
BOOL fIgnore;
// Perform actions based on the reason for calling.
switch( fdwReason )
{
case DLL_PROCESS_ATTACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
std::cout << "thread detached in DLL Main" << std::endl;
break;
case DLL_PROCESS_DETACH:
break;
default:
break;
}
return TRUE;
}
void myDLLFuntion(int i)
{
scoped_lock_recursive lock(mutex);
if (current_thread_index.get() == NULL)
{
current_thread_index.reset(new unsigned int());
std::cout << i << " new thread attached!" << std::endl;
}
}
Code that use the DLL:
====================
void doThread(int i)
{
myDLLFuntion(i);
}
int main(VOID)
{
boost::thread thrd1(boost::bind(doThread,1));
thrd1.join();
}
output on cosole:
===============
1 new thread attached!
thread detached in DLL Main
But the cleanup funtion is not called. Any Idea?
If i move the myDllFuntion, void detach_thread funtion and the declaration of the boost::thread_specific_ptr<unsigned int> current_thread_index(&detach_thread) from the dll to the file where the main funtions is defined everything works as expected.
regards
rudi