Search code examples
c++qtprogram-entry-pointfreeze

Qt/C++ application stucks before main() starts when using singleton from DLL


We have a Qt-based application.

Today I was working on extracting of some resources and code into separate DLL.

As soon as I start using DLL instead of the local classes, I got very strange behavior:

Application gets stuck even BEFORE hitting main() function.

Does anybody has ANY idea what might be wrong? I don't know where to dig, so don't know what's relevant here.

We are using cmake 3.4 to configure project, Qt 5.4, Visual Studio 2012.

UPDATE. According to VS output application starts and successfully loads all the dlls. So I can see the console window, which is empty.

UPDATE 2. @Martin James, almost the right answer. The problem was in a singleton initialization, which used mutex. I don't understand completely why, but it stucks on mutex if called during DLL loading.

UPDATE 3. In a kind of way it's a duplicate of C++11 std::mutex in Visual Studio 2012 deadlock when locked from DllMain(). When asking the question, the reason of the lock was unknown.


Solution

  • Attempting to explicitly prevent multiple access in DLL initialization with a mutex can result in deadlock for reasons best known to MS:(

    Cannot lock a c++ 11 std::mutex on a DLL https://connect.microsoft.com/VisualStudio/feedback/details/809005/deadlock-when-locking-std-mutex-during-dllmain-static-initialization