The other day I ran into an issue where a thread got stuck on accessing a singleton. It was quite curious because there was no locking with mutexes or critical sections going on, yet the thread stalled. The callstack showed
init_thread_wait as the top most functions of the callstack, so the thread was definitely waiting for something... As it turns out, the constructor of the singleton class was calling some functions, which in turn would try to access the singleton again, this would of course result in an endless loop, depending on which implementation of singletons you use.
If you would instantiate the singleton with
new, there would be an endless loop, and the stack would overflow. But if you used a static instance, the thread would simply stall at completion of the first loop, and Visual Studio would not complain, warn, or break.
Here is a simple example of how you can recreate this issue.
static MySingleton& GetInstance()
static MySingleton instance;
MySingleton::GetInstance(); // This is obviously bad
Of course the code I was working with was not so straightforward. So you would definitely have to look at the entire callstack to find the source of the problem.
Interesting issue, something to look out of in case your code stalls while accessing a singleton. But then again, we probably shouldn't be calling any functions in constructors anyway... 🙂
In case you would like to use the latest version of Qt using OpenGL instead of ANGLE in combination with Visual Studio 2012 and target a 32-bit platform you will be disappointed to find out that there are no precompiled libraries available from the Qt-Project website...
Instead of using precompiled libraries you need to compile Qt yourself if you still want to use Qt with Visual Studio 2012.
In order to compile Qt you first need a couple of prerequisites, be sure to get the 32-bit versions.
- Download and install Python http://www.python.org/getit/ (x86).
- Download and install Perl http://strawberryperl.com/ (32 bit).
- Download jom http://qt-project.org/wiki/jom.
- Download and extract the Qt sources from http://qt-project.org/downloads.
- You need to find the zip for windows, it's below all the installer downloads.
- Copy the jom contents to the Qt sources directory.
- Make sure python and perl are accessible everywhere from the commandline by testing "python --version" and "perl -v".
Compiling the Qt sources
- Open the Visual Studio 2012 command prompt.
- It should be located in Start > Microsoft Visual Studio 2012 > Visual Studio Tools > VS2012 x86 Native Tools Command Prompt.
- Be sure you are opening the x86 version and not the x64 version!
- Navigate to the Qt sources directory by using "cd <directory here>".
- Type "configure -developer-build -opensource -opengl desktop -nomake examples -nomake tests"
- It should ask you to accept the terms of the license.
- Then it should start configuring the Qt sources for compilation, this will just take a minute.
- Finally type "jom" to compile Qt.
- This can take a long time, around 30-60 minutes depending on how fast your computer is. It took me 50 minutes to compile...
Integrating Qt with Visual Studio 2012
After you compiled the Qt libraries you can install the Visual Studio 2012 Add-in for Qt to make life easier. You can get the Add-in from the downloads page under "Other downloads": http://qt-project.org/downloads.
In Visual Studio 2012 I pointed Qt to the qtbase directory in the Qt sources directory by going in the Qt Options. Qt5 > Qt Options. Add a new Qt version and select the qtbase directory, pick a suitable name and press OK. Use this Qt version in your project and you should be able to compile for 32-bit platforms.