ref isolate loop
This commit is contained in:
parent
f9a47debfc
commit
de78922b12
@ -2649,6 +2649,9 @@ void StartThread(node::Isolate* isolate,
|
||||
if (isolate->id_ > 1) {
|
||||
process_l->Set(String::NewSymbol("_send"),
|
||||
FunctionTemplate::New(Isolate::Send)->GetFunction());
|
||||
|
||||
process_l->Set(String::NewSymbol("_exit"),
|
||||
FunctionTemplate::New(Isolate::Unref)->GetFunction());
|
||||
}
|
||||
|
||||
// FIXME crashes with "CHECK(heap->isolate() == Isolate::Current()) failed"
|
||||
|
@ -135,6 +135,8 @@
|
||||
msg = JSON.parse('' + msg);
|
||||
process.emit('message', msg);
|
||||
};
|
||||
|
||||
process.exit = process._exit;
|
||||
}
|
||||
|
||||
startup.globalVariables = function() {
|
||||
|
@ -215,6 +215,16 @@ Handle<Value> Isolate::Send(const Arguments& args) {
|
||||
}
|
||||
|
||||
|
||||
Handle<Value> Isolate::Unref(const Arguments& args) {
|
||||
HandleScope scope;
|
||||
|
||||
Isolate* isolate = Isolate::GetCurrent();
|
||||
uv_unref(isolate->loop_);
|
||||
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
|
||||
void Isolate::OnMessage(IsolateMessage* msg, void* arg) {
|
||||
HandleScope scope;
|
||||
|
||||
@ -270,6 +280,11 @@ Isolate::Isolate() {
|
||||
assert(v8_isolate_->GetData() == NULL);
|
||||
v8_isolate_->SetData(this);
|
||||
|
||||
// Artificially ref the isolate loop so that the child
|
||||
// isolate stays alive by default. process.exit will
|
||||
// unref the loop (see Isolate::Unref).
|
||||
uv_ref(loop_);
|
||||
|
||||
globals_init_ = false;
|
||||
}
|
||||
|
||||
|
@ -74,6 +74,7 @@ public:
|
||||
typedef void (*AtExitCallback)(void* arg);
|
||||
|
||||
static v8::Handle<v8::Value> Send(const v8::Arguments& args);
|
||||
static v8::Handle<v8::Value> Unref(const v8::Arguments& args);
|
||||
|
||||
static Isolate* GetCurrent() {
|
||||
return reinterpret_cast<Isolate*>(v8::Isolate::GetCurrent()->GetData());
|
||||
|
@ -52,6 +52,7 @@ if (process.tid === 1) {
|
||||
fs.stat(__dirname, function(err, stat) {
|
||||
if (err) throw err;
|
||||
console.error('thread 2', stat.mtime);
|
||||
process.exit();
|
||||
});
|
||||
}, 500);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user