Author Topic: Problems with dynamically loaded DLLs and with recursive_mutex  (Read 53607 times)

adumais

  • Newbie
  • *
  • Posts: 2
    • View Profile
Problems with dynamically loaded DLLs and with recursive_mutex
« on: November 09, 2011, 09:15:00 PM »
Hello,

I downloaded v1.7.2 and it fixed the warning LNK4099, so thanks!

Now we went further in integrating just::thread in our applications and encountered 2 new problems.

PROBLEM #1

When a DLL using justthread_check_vc10x64_mdd.lib is dynamically loaded with LoadLibrary, we get a crash.

For example (otxt.dll is our dynamically loaded DLL that uses Just::Thread) :

               msvcr100d.dll!_NMSG_WRITE()  + 0x9f octets 
               msvcr100d.dll!abort()  + 0x24 octets     
>>>>>   otxt.dll!__jss::`anonymous namespace'::`dynamic initializer for 'sym_manager''()  Ligne 309 + 0x2a octets        C++
               msvcr100d.dll!_initterm()  + 0x2c octets             
               otxt.dll!_CRT_INIT(void * hDllHandle, unsigned long dwReason, void * lpreserved)  Ligne 289 C
               otxt.dll!__DllMainCRTStartup(void * hDllHandle, unsigned long dwReason, void * lpreserved)  Ligne 506 + 0x13 octets   C
               otxt.dll!_DllMainCRTStartup(void * hDllHandle, unsigned long dwReason, void * lpreserved)  Ligne 477             C
               ntdll.dll!000000007763b0d8()     
                [Les frames ci-dessous sont peut-être incorrects et/ou manquants, aucun symbole chargé pour ntdll.dll]         
               ntdll.dll!000000007762784a()     
                ntdll.dll!0000000077627b2e()     
                KernelBase.dll!000007fefdd2c71f()       
                KernelBase.dll!000007fefdd2a951()       
                kernel32.dll!00000000773970a4()           
                obase.dll!rdll_Open(const char * ModuleName)  Ligne 28 + 0xe octets               C++
               obase.dll!msg_DllInit(const char * DllName)  Ligne 31 + 0xa octets         C++
               obase.dll!err_SetExecMode(err_ExecMode_ch Mode)  Ligne 36 + 0xc octets  C++
               iniget.exe!mainImpl(int argc, char * * argv)  Ligne 37    C++
               iniget.exe!main(int argc, char * * argv)  Ligne 229 + 0xe octets C++
               iniget.exe!__tmainCRTStartup()  Ligne 555 + 0x19 octets            C
               iniget.exe!mainCRTStartup()  Ligne 371               C
               kernel32.dll!000000007739652d()           
                ntdll.dll!000000007762c521()     

There's only one thread started in the process when that crash occurs.

This problem is not encountered with justthread_vc10x64_mdd.lib.


PROBLEM #2

With justthread_vc10x64_mdd.lib (since we're a bit stuck with the check version), there is another problem.

I get a crash in a thread that has not been started using std::thread and that is trying tu use a recursive_mutex:

>             obase.dll!__jss::__recursive_mutex_impl<__jss::mutex>::__owned_by_this_thread()  Ligne 43 + 0x5 octets                C++
               obase.dll!__jss::__recursive_mutex_impl<__jss::mutex>::lock()  Ligne 81 + 0xa octets              C++
               obase.dll!std::recursive_mutex::lock()  Ligne 164           C++
               obase.dll!std::lock_guard<std::recursive_mutex>::lock_guard<std::recursive_mutex>(std::recursive_mutex & m_)  Ligne 70               C++
               obase.dll!rms_ObjectClose(void * Handle)  Ligne 33 + 0x11 octets         C++
               [Code externe]               
               owrapnet.DLL!wrms_Component_c::!wrms_Component_c() Ligne 68                C++
               [Code externe]               
               kernel32.dll!000000007739652d()           
                [Les frames ci-dessous sont peut-être incorrects et/ou manquants, aucun symbole chargé pour kernel32.dll]               
               ntdll.dll!000000007762c521()     

This thread was created before obase.dll (that uses JustThread) was loaded. Someone here suspects that it is related to that fact. We had a similar problem with Thread Local Storage a couple of years ago: when declaring a TLS in a DLL using Microsoft approach, the storage was not automatically created for threads that existed prior to loading that DLL, we had to implement something for that special case.

These threads are created by the system, so on our side we have no control over them, hence no possible workaround...

Otherwise, recursive_mutex seems to work properly on the main thread.

Any cue about these issues?

Thanks a lot!
Alexandre

Anthony Williams

  • Administrator
  • Full Member
  • *****
  • Posts: 103
    • View Profile
    • just::thread C++ Thread Library
Re: Problems with dynamically loaded DLLs and with recursive_mutex
« Reply #1 on: November 09, 2011, 09:29:19 PM »
PROBLEM #1
When a DLL using justthread_check_vc10x64_mdd.lib is dynamically loaded with LoadLibrary, we get a crash.

PROBLEM #2
With justthread_vc10x64_mdd.lib (since we're a bit stuck with the check version), there is another problem.

I get a crash in a thread that has not been started using std::thread and that is trying tu use a recursive_mutex:

This thread was created before obase.dll (that uses JustThread) was loaded. Someone here suspects that it is related to that fact. We had a similar problem with Thread Local Storage a couple of years ago: when declaring a TLS in a DLL using Microsoft approach, the storage was not automatically created for threads that existed prior to loading that DLL, we had to implement something for that special case.

This does sound like a TLS issue in both cases. The "check" library uses TLS for keeping track of the check data, and recursive_mutex uses TLS for fast recursive locking. I thought we'd avoided the Microsoft TLS problems, but it would appear not. I'll add some more test cases for dynamically-loaded DLLs to our test suite and issue a fix for 1.7.3.