What you're asking appears to be possible, and quite easy.
First, see the following link for how multithreading seems to work in
V8. You'll find that it won't be necessary to modify V8 and make it
threadsafe (not to mention a huge undertaking).
http://groups.google.com/group/v8-users/browse_thread/thread/3f66bb4cf86d836e/163379d7082c317d?#163379d7082c317d
With that all in mind, take a look at how you compile and run a
script. The class Script has two methods: Compile and Run. When you
Compile a script, it gives you back a Local handle to a Script object
(suggesting that Script privately holds the result of compilation).
Problem is, since it's Local and not Persistent, it (along with the
result of compilation) will be destroyed as soon as you leave the
current scope, so it can't be shared among threads. The v8::Persistent
class, however, provides a way to duplicate handles with the New
method. Pass your Local<Script> into Persistent::New, and your Script
object becomes persistent in the garbage collector.
Code would look something like this (untested)-
Local<Script> local_compiled_script = Script::compile("var i=0;
while(i<1000) { i++; }"); // Compile a script, and store a
Local:Handle to it
Persistent<Script> persistent_compiled_script =
Persistent::New(local_compiled_script); // Create a new
Persistent:Handle, and initialize it with the object referenced in the
local_compiled_script handle
...and now you can call persistent_compiled_script->Run() as many
times as you want in as many different places as you want, and the
Script object will not be garbage collected since it's now the subject
of a Persistent handle.