Calling javascript functions via QJSEngine from multiple threads possible?

  • Hi,

    I am working on a multithreaded application, and I try to use Javascript functions in this application, i.e. the worker threads would evaluate some JS code during their execution. What I found is the following:
    when I use the new QJSEngine (the v8 stuff), and when I try the following (by calling run()), the program crashes:

    QJSEngine *script_engine; // global variable
    function run_func()
    QJSValue result = engine->evaluate("1+1");

    function run()
    script_engine = new QScriptEngine;
    QList<int> jobs;
    for (int i=0;i<100;++i) jobs.append(i);
    qDebug() << "starting jobs...";
    QtConcurrent::blockingMap (jobs, run_func );
    qDebug() << "jobs finished";
    delete script_engine;

    it plots an message [after the "starting jobs..." line]:

    Fatal error in q:\qt5_workdir\w\s\qtjsbackend\src\3rdparty\v8\src\isolate.h, line 446

    CHECK(isolate != 0) failed

    I use Qt 5.1.1, and MSVC2010 32bit.

    For me it looks as if only one thread can use the JS-Engine (note: this is a console app, no GUI or QML around). However, hints otherwise (and is closed). I did not find much in the documentation about that...
    I tried the same thing with the "old" QScriptEngine, and the result was similar, i.e. a crash but here without a nice warning.

    So the questions are:
    (1) can a Javascript engine be used from multiple threads (QtConcurrent)?
    (2) can I use multiple Javascript-engines in parallel (one engine for each thread) [I tried this briefly but got the same CHECK-error in "isolate.h"]?
    (3) are there differences between QJsEngine and QScriptEngine with regard to multithreaded script execution?

    thanks a lot for your answers!


  • Hi,

    I encountered the same problem and filed a bugreport on it.
    Please upvote it.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.