Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

isolates: make main thread reap subordinate threads

  • Loading branch information...
commit 6228172ae832e45e5952d51ef173b994229f5e78 1 parent 0a0322a
@bnoordhuis bnoordhuis authored
Showing with 18 additions and 15 deletions.
  1. +18 −15 src/node.cc
View
33 src/node.cc
@@ -97,7 +97,7 @@ extern char **environ;
#include <node_vars.h>
-#include "atomic_ops.h"
+#include <node_atomic.h>
// We do the following to minimize the detal between v0.6 branch. We want to
// use the variables as they were being used before.
@@ -1837,26 +1837,14 @@ static unsigned long NewThreadId() {
}
+// TODO break up in definition and implementation and move to separate files
struct ThreadInfo {
+ AtomicQueueEntry queue_entry_;
unsigned long thread_id_;
uv_thread_t thread_;
char** argv_;
int argc_;
- ThreadInfo(int argc, char** argv) {
- thread_id_ = NewThreadId();
-
- argc_ = argc;
- argv_ = new char*[argc_ + 1];
-
- for (int i = 0; i < argc_; ++i) {
- size_t size = 1 + strlen(argv[i]);
- argv_[i] = new char[size];
- memcpy(argv_[i], argv[i], size);
- }
- argv_[argc_] = NULL;
- }
-
ThreadInfo(Handle<Array> args) {
argc_ = args->Length();
argv_ = new char*[argc_ + 1];
@@ -1868,17 +1856,27 @@ struct ThreadInfo {
memcpy(argv_[i], *str, size);
}
argv_[argc_] = NULL;
+
+ active_threads_.Insert(this);
}
+
~ThreadInfo() {
+ active_threads_.Remove(this);
+
for (int i = 0; i < argc_; ++i) {
delete[] argv_[i];
}
delete[] argv_;
}
+
+ static AtomicQueue<ThreadInfo> active_threads_;
};
+AtomicQueue<ThreadInfo> ThreadInfo::active_threads_;
+
+
static void RunIsolate(void* arg) {
ThreadInfo* ti = reinterpret_cast<ThreadInfo*>(arg);
@@ -2762,6 +2760,11 @@ int Start(int argc, char *argv[]) {
StartThread(NewThreadId(), isolate, argc, argv);
isolate->Dispose();
+ while (ThreadInfo* ti = ThreadInfo::active_threads_.Pop()) {
+ if (uv_thread_join(&ti->thread_))
+ abort();
+ }
+
#ifndef NDEBUG
// Clean up.
V8::Dispose();
Please sign in to comment.
Something went wrong with that request. Please try again.