Hi,
I´ve made several tests with TerminateExecution() running the endless loop
with sleep.
As I mentioned, the test environment was:
1 Isolate, 1 common Context, 1 global object
Several threads – using v8::Lock/Unlock running the JS functions:
while(true) { sleep(1); } – where sleep is a JS FunctionTemplate extension
and it does what its name suggests.
Call TerminateExecution() for all of the threads running the JS function.
The result was almost every time that 1 thread did not terminate the JS
function. However in some cases it worked fine. I just wanted to see more
info, so I modified the JS script:
counter = {};
counter[scriptName] = 0;
while(true){
++counter[scriptName];
sleep(1);
}
The global variable counter is an object containing the loop count for each
script. scriptName was different in each thread running the JS function.
Before I called TerminateExecution(), I set counter[scriptName] = 0;
And … it worked. All threads terminated the execution. The loop counts were
between some hundreds to some thousands.
It seemed to be a timing Problem. I’ve produced more loads on the computer,
and I repeated the tests. And it happened again. One thread did not
terminate the execution. All other threads – I‘ve tested up to 10 threads –
terminated the execution with some thousands loop count, but 1 was still
running. And it was not always the same. But I could display the loop
count. I waited more than 600000 and one time I left to run through the
night – no termination.
I wanted to stop the execution with the following JS function: ‘counter =
{}’. I started this function in another thread, and expected a
ReferenceError Exception as counter[scriptName] did not exist anymore. The
execution terminated with an Exception; however it was an uncaughtable
Exception. That should be produced by TerminateExecution().
As I understand, it means, that the v8 thread recognized the
TerminateExecution() request, but it did not stop the iteration of the
termination.
Unfortunately I cannot reproduce this behavior in simple test case. It just
happens in my application. I hope, this info is useful for the development.
The tests showed, that requesting the termination may take several
thousands of iterations and in some cases the iteration does not terminate
– interestingly always only for one thread. I could not find any public v8
functions that reflect this state of the v8 thread: iterating for
termination. Is it possible to interrogate this state? If not, it would be
nice to have a function like v8::V8::IsExecutionTerminationRequested().
Time consuming C++ extensions could be aborted without waiting for end of
termination iteration.
Thank you,
Laszlo
On Monday, April 8, 2013 4:28:54 PM UTC+2, Laszlo Szakony wrote:
>
> I understand 'in parallel' that the threads running the JS functions use
> the same Context hence the same global object - with every implication of
> course. The synchronization is done by v8::Locker, so no thread is
> accessing the isolate without acquiring the v8::Lock. Sorry for the
> confusion. The question is still, if some circumstances exists,
> where TerminateExecution() does not terminate the execution of a running JS
> function in such an environment?
>
> Am Montag, 8. April 2013 16:13:08 UTC+2 schrieb Jakob Kummerow:
>>
>> Earlier you said that "several scripts are running [in] parallel".
>> That's precisely what's not supported. Sven was pointing out that when
>> several threads need to access an isolate, they can do so, but only *one at
>> a time*. No two threads can be allowed to run in the same isolate at the
>> same time, or very weird things will begin to happen (the observation about
>> the constant sum of loop counts is just a mildly amusing, harmless example;
>> you could also have data loss, crashes and whatnot).
>>
>>
>> On Mon, Apr 8, 2013 at 3:35 PM, Laszlo Szakony <[email protected]>wrote:
>>
>>> That`s what I`m doing. I have one Context in the default isolate - one
>>> global object - and several threads running JS functions. Each thread uses
>>> v8::Locker for synchronization.
>>> Can I call in this case TerminateExecution() for each thread or not? It
>>> seems to work up to the sleep() problem, where 1 thread remains running.
>>>
>>> Am Montag, 8. April 2013 15:17:13 UTC+2 schrieb Sven Panne:
>>>
>>>> Just a quick drive-by comment: You *can* use an Isolate from various
>>>> threads, but you'll have to use a v8::Locker in all threads then. This
>>>> way,
>>>> you inform v8 about your thread switches and make sure that at any given
>>>> point in time at most one thread is actively using an Isolate.
>>>>
>>> --
>>> --
>>> v8-users mailing list
>>> [email protected]
>>> http://groups.google.com/group/v8-users
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "v8-users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>>
>>
--
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.