[Interest] QScriptProgram and multi-threading

Christian Schneider mail at chrschn.de
Mon Jan 21 16:13:02 CET 2013



On 01/21/13 15:31, Tony Rietwyk wrote:
> 
>> Sent: Monday, 21 January 2013 11:32 PM
>>
>> Hi all.
>>
>> I have written a multi-threaded program (Qt 4.8.3) that executes QtScript
>> code in multiple threads, each thread with its own QScriptEngine. The
> script
>> code is wrapped in QScriptProgram object.
>>
>> Is the same QScriptProgram object supposed to be usable in multiple script
>> engines concurrently? If the answer is yes, I think I found a bug, because
> it
>> seems that this is not the case. (I'm happy to file a bug report then). If
> the
>> answer is no, the API documentation of QScriptProgram and QScriptEngine is
>> misleading and should be updated.
>>
>> To find the root cause for the problem, I tried to analyze the threads
> using
>> Helgrind, and it spits out a lot of errors like the following:
>> http://img145.imageshack.us/img145/9094/helgrind.png
>>
>> This seems to be consistent with what I see in the debugger: When my
>> application crashes, at least one of the threads almost always is in the
> control
>> path of some JIT-related functions of the JS engine.
>>
>> Any thoughts would be welcome.
>>
>> -Christian
> 
> Hi, 
> 
> I don't see anything in the 4.8.4 docs to suggest they can be shared between
> threads.   Even though they might be executing the same program script, I
> think you'll need to create a separate one for each thread.  
> 
> Tony

Hi Tony.

You are right, the docs don't explicitly state "QScriptProgram may be
shared". However, QScriptEngine::evaluate() takes a constant reference
to the QScriptProgram as an argument, so I was under the impression that
it is used read-only and can thus be shared among multiple threads
(that's what I meant with "misleading docs" in my first post).

Anyway, thanks for your answer.

-Christian

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 263 bytes
Desc: OpenPGP digital signature
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130121/f580083b/attachment.sig>


More information about the Interest mailing list