Details
-
Bug
-
Resolution: Won't Do
-
Not Evaluated
-
None
-
4.8.4
-
None
-
Gentoo Linux, AMD64
Description
Evaluating the same QScriptProgram object in a multi-threaded application with separate QScriptEngines per thread causes a segfault, even though the program is passed in as a constant reference to evaluate(). Here's a small main.cpp to reproduce the error:
#include <QtCore> #include <QtScript> QScriptProgram prog("o = { foo: 123, bar: 456 }; o = null; gc()"); class Thread : public QThread { protected: virtual void run() { QScriptEngine engine; while (1) { engine.evaluate(prog); } } }; int main(int argc, char **argv) { QCoreApplication app(argc, argv); Thread threads[2]; for (int i = 0; i < 2; ++i) threads[i].start(); return app.exec(); }
In debug mode, the following output is generated:
ASSERTION FAILED: !m_deletionHasBegun
(../3rdparty/javascriptcore/JavaScriptCore/wtf/RefCounted.h:36 void QTWTF::RefCountedBase::ref())
The segfault also occurs when evaluating a copy of the QScriptProgram:
QScriptProgram prog("o = { foo: 123, bar: 456 }; o = null; gc()"); class Thread : public QThread { protected: virtual void run() { QScriptEngine engine; QScriptProgram p(prog); while (1) { engine.evaluate(p); } } };
Interestingly enough, the program works fine when creating the per-thread QScriptProgram using the string-based constructor:
QScriptProgram prog("o = { foo: 123, bar: 456 }; o = null; gc()"); class Thread : public QThread { protected: virtual void run() { QScriptEngine engine; QScriptProgram p(prog.sourceCode()); while (1) { engine.evaluate(p); } } };