I'm trying to familiarize myself with v8, it's structure and
capabilities, seeing how it can be used as an embedded scripting
language. I haven't really had much hands-on experience yet so I'm
hoping my poking around isn't too stupid or way off in left-field
here, I do have some questions about threading however.
With javascript in normal browsers, I'm fairly certain that there is
only one thread active (from the point of view of the script anyhow).
While a single function is running no events occur, the screen may not
even update, and the page in general goes unresponsive (I'm talking in
general, my experience is mostly with IE, Chrome may be different).
Google Gears attempts to add the concept of multithreading to
JavaScript but the communication pathway is extremely limited, I'm
guessing to prevent interaction between scripts running in the two
pages.
I'm going to assume that the V8 "context" refers to a "web page" (i.e.
in a browser each web page maps to a single and separate context). My
first question is whether V8 permits multiple threads within a
context, whether execution of javascript within a context has been
serialized (i.e. if you call a function in a context while a second
thread is already calling a function in the same context, does the
second thread block on the first?), and if V8 can somehow permits
multithreading within a context (which I really doubt), how would the
javascript code running in the context be affected by this (suddenly
needing to do its own mutexing?).
The second question has to do with suspending threads of execution.
In a browser there are a number of long-running commands that contain
what I describe as "their own message pump". If you do an alert('hi')
or issue a synchronous XHR request then you are liable to find some of
your own code executing beneath that call on the call stack (whether
triggered by an event, setTimeout, or whatever). Otherwise the thread
is effectively idle, waiting for user input or for response from a
server. The embedded equivalent I'm assuming would be that the C++
code is re-entered, presumably with a very lengthy c++ call stack. I
would like to avoid locking a large number of threads as idle if
possible, although I'm guessing that the JavaScript state cannot be
suspended while in the middle of a function call.
Has anyone explored assigning operating system fibers to javascript
contexts? This would permit one to "shelve" threads of execution
while in the middle of a function call, although it does add the
responsibility of managing and assigning fibers to threads. Does V8
care if it unexpectedly finds itself running on a different os thread,
or would it even notice? Or is this overkill?
My third question would be regarding governors to prevent runaway
script or memory usage. From what I've read in other threads though
there is no surefire way to interrupt a running script (DebugBreak?),
although there may be some discussion on installing an interrupt
somewhere.
--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---