Skip to content
This repository
Browse code

ref isolate loop

  • Loading branch information...
commit de78922b12c06b80489ec8eb05f0e3d4cd3fe8fa 1 parent f9a47de
Igor Zinkovsky authored
3  src/node.cc
@@ -2649,6 +2649,9 @@ void StartThread(node::Isolate* isolate,
2649 2649 if (isolate->id_ > 1) {
2650 2650 process_l->Set(String::NewSymbol("_send"),
2651 2651 FunctionTemplate::New(Isolate::Send)->GetFunction());
  2652 +
  2653 + process_l->Set(String::NewSymbol("_exit"),
  2654 + FunctionTemplate::New(Isolate::Unref)->GetFunction());
2652 2655 }
2653 2656
2654 2657 // FIXME crashes with "CHECK(heap->isolate() == Isolate::Current()) failed"
2  src/node.js
@@ -135,6 +135,8 @@
135 135 msg = JSON.parse('' + msg);
136 136 process.emit('message', msg);
137 137 };
  138 +
  139 + process.exit = process._exit;
138 140 }
139 141
140 142 startup.globalVariables = function() {
15 src/node_isolate.cc
@@ -215,6 +215,16 @@ Handle<Value> Isolate::Send(const Arguments& args) {
215 215 }
216 216
217 217
  218 +Handle<Value> Isolate::Unref(const Arguments& args) {
  219 + HandleScope scope;
  220 +
  221 + Isolate* isolate = Isolate::GetCurrent();
  222 + uv_unref(isolate->loop_);
  223 +
  224 + return Undefined();
  225 +}
  226 +
  227 +
218 228 void Isolate::OnMessage(IsolateMessage* msg, void* arg) {
219 229 HandleScope scope;
220 230
@@ -270,6 +280,11 @@ Isolate::Isolate() {
270 280 assert(v8_isolate_->GetData() == NULL);
271 281 v8_isolate_->SetData(this);
272 282
  283 + // Artificially ref the isolate loop so that the child
  284 + // isolate stays alive by default. process.exit will
  285 + // unref the loop (see Isolate::Unref).
  286 + uv_ref(loop_);
  287 +
273 288 globals_init_ = false;
274 289 }
275 290
1  src/node_isolate.h
@@ -74,6 +74,7 @@ class Isolate {
74 74 typedef void (*AtExitCallback)(void* arg);
75 75
76 76 static v8::Handle<v8::Value> Send(const v8::Arguments& args);
  77 + static v8::Handle<v8::Value> Unref(const v8::Arguments& args);
77 78
78 79 static Isolate* GetCurrent() {
79 80 return reinterpret_cast<Isolate*>(v8::Isolate::GetCurrent()->GetData());
1  test/simple/test-isolates0.js
@@ -52,6 +52,7 @@ if (process.tid === 1) {
52 52 fs.stat(__dirname, function(err, stat) {
53 53 if (err) throw err;
54 54 console.error('thread 2', stat.mtime);
  55 + process.exit();
55 56 });
56 57 }, 500);
57 58

0 comments on commit de78922

Please sign in to comment.
Something went wrong with that request. Please try again.