Execution termination - how exactly?

23 views
Skip to first unread message

ondras

unread,
Sep 3, 2009, 7:05:08 AM9/3/09
to v8-users
Hi,

how exactly is the new feature "execution termination" supposed to
work? I created a JS function "exit", which performs
"v8::V8::TerminateExecution()". However, the following code:

doSomething();
exit();
doSomethingElse();

seems to ignore the termination command, because doSomethingElse gets
normally executed...


Thanks,
Ondrej

Mads Sig Ager

unread,
Sep 3, 2009, 7:12:33 AM9/3/09
to v8-u...@googlegroups.com
Hi Ondrej,

the actual termination is not carried out immediately but at the next
stack guard check. If your doSomethingElse is trivial enough, it will
not trigger a stack guard check. However, if it contains calls or
loops it should hit the termination.

Have a look at test/cctest/test-thread-termination.cc for examples.

Cheers, -- Mads

Xiang

unread,
Nov 23, 2009, 9:54:59 AM11/23/09
to Mads Sig Ager, v8-u...@googlegroups.com
Hi, Mads,

You mentioned that "if...is trivial enough, it will not trigger a
stack guard check. "

I found the following script can't be terminated by
v8::V8::TerminateExecution(), is it caused by the reason you mentioned
above?

for (;;)
{
print("Still running");
}


If we want to terminate the above script, what should we do?
There is another overloaded API v8::V8::TerminateExecution(int
threadID), will that works?


Reproduction steps:
-----------------------------
There is a test-thread-termination.cc under project ccTest,
Change function Doloop to following, then the test case
"test-thread-termination/TerminateOnlyV8ThreadFromThreadItself" will
fail
v8::Handle<v8::Value> DoLoop(const v8::Arguments& args) {
v8::TryCatch try_catch;
//v8::Script::Compile(v8::String::New("function f() {"
// " var term = true;"
// " try {"
// " while(true) {"
// " if (term) terminate
();"
// " term = false;"
// " }"
// " fail();"
// " } catch(e) {"
// " fail();"
// " }"
// "}"
// "f()"))->Run();
v8::Script::Compile(v8::String::New("var term = true; while(true)
{if
(term) terminate(); term = false;}"))->Run();
CHECK(try_catch.HasCaught());
CHECK(try_catch.Exception()->IsNull());
CHECK(try_catch.Message().IsEmpty());
CHECK(!try_catch.CanContinue());
return v8::Undefined();

Reply all
Reply to author
Forward
0 new messages