I have an interesting problem, that I just can't seem to crack.

The problem:
I need to interleave the execution of two scripts.  For example script
1 executes one line, then script 2 executes one line, then script 1
executes another line, etc.  Once one of the scripts finishes I need
to cancel/terminate the other.


My solution:
I'm using an Isolate for each script, so that they don't interact via
v8 at all.  Each script is run from it's own thread.

* Use a v8::Locker lock( isolate) at the top of the thread function

* Send the message { "seq": x, "type": "request", "command":
"continue", "arguments": { "stepaction": "in" } }

* v8::Debug::DebugBreak( isolate );

* Run the script

* in the callback from v8::Debug::SetDebugEventListener2 I send
another continue message

* in the callback from v8::Debug::SetMessageHandler2 I send another
continue message (note that's two!)
In the callback I also block the scripts thread on a semaphore.  The
semaphore is posted (lets the script thread unblock and continue)
after the other script executes a line.

* Once the other script finishes v8::TerminateExecution( isolate ) is
sent.

* The program waits for the v8 thread to exit, then calls Dispose on
the Isolate.


My Questions:
Does this look reasonable?  It's odd that I have to send a continue
command from both the message and event callback.  But If I only do it
from one or the other, the v8 thread hangs waiting for a continue
command.

Also occasionally (maybe a quarter of the time) the thread will not
shutdown.  When I look into the app with a debugger I see it
repeatedly calling v8::internal::Debug_Break.  I assume the frames
higher on the stack are jit code as gdb knows nothing about them.

Does anyone have thoughts that could help fix the hang or a different
approach that might work better?

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to