Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-29246

Using QScriptProgram in multiple threads causes segfault

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Do
    • Not Evaluated
    • None
    • 4.8.4
    • Qt Script
    • 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);
              }
          }
      };
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            laknoll Lars Knoll
            chrschn Christian Schneider
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes