Could this be a possible bug for Qt's SQL database?
-
I have met a problem stated in this question: http://qt-project.org/forums/viewthread/49138/
After I have done some research and asked some of my friends. I found that the default constructor of
QSqlDatabase might be the problem.Here is the thing:
The default constructor of QSqlDatabase used a shared_null.
Note that the shared_null is an object indicating an invalid database, not a plain null pointer.Here is the code: http://code.woboq.org/qt5/qtbase/src/sql/kernel/qsqldatabase.cpp.html#_ZN19QSqlDatabasePrivate11shared_nullEv
You can see these are static variables in the function, and -- static variable initialization is not thread-safe!
See:
http://blogs.msdn.com/b/oldnewthing/archive/2004/03/08/85901.aspx
http://www.codeguru.com/cpp/misc/misc/assemblylanguage/article.php/c12897/Function-Static-Variables-in-MultiThreaded-Environments.htmSo, if you call these default constructors in different threads, there might be problems, in my case, my suspicion is that the shared_null is initialized twice due to this kind of race condition. As a result, the ref counting went wrong and the delete is called on this static object (which should not be delete-able).
I am new to Qt, any one have great ideas about this?
-
Hi,
That question would be more suited for the interest mailing list. You'll find there Qt's developers/maintainers (this forum is more user oriented)