Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Unified Diff: samples/shell.cc

Issue 6624071: [Isolates] Use _exit() instead of exit() in shell to avoid shutdown (Closed)
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samples/shell.cc
diff --git a/samples/shell.cc b/samples/shell.cc
index 0f040db5681b58f7eb55412997b3d5f027110fe4..6afa524ceb985ca74c9d38542a90804572bbb18e 100644
--- a/samples/shell.cc
+++ b/samples/shell.cc
@@ -41,8 +41,17 @@
// o Do not assume not WIN32 implies pthreads.
#ifndef WIN32
#include <pthread.h> // NOLINT
+#include <unistd.h> // NOLINT
#endif
+static void ExitShell(int exit_code) {
+ // Use _exit instead of exit to avoid races between isolate
+ // threads and static destructors.
+ fflush(stdout);
+ fflush(stderr);
+ _exit(exit_code);
+}
+
v8::Persistent<v8::Context> CreateShellContext();
void RunShell(v8::Handle<v8::Context> context);
bool ExecuteString(v8::Handle<v8::String> source,
@@ -94,7 +103,7 @@ class SourceGroup {
v8::Handle<v8::String> file_name = v8::String::New("unnamed");
v8::Handle<v8::String> source = v8::String::New(argv_[i + 1]);
if (!ExecuteString(source, file_name, false, true)) {
- exit(1);
+ ExitShell(1);
return;
}
++i;
@@ -109,7 +118,7 @@ class SourceGroup {
printf("Error reading '%s'\n", arg);
}
if (!ExecuteString(source, file_name, false, true)) {
- exit(1);
+ ExitShell(1);
return;
}
}
@@ -133,8 +142,8 @@ class SourceGroup {
pthread_attr_setstacksize(&attr, stacksize);
int error = pthread_create(&thread_, &attr, &IsolateThreadEntry, this);
if (error != 0) {
- printf("Error creating isolate thread.\n");
- exit(1);
+ fprintf(stderr, "Error creating isolate thread.\n");
+ ExitShell(1);
}
}
next_semaphore_->Signal();
@@ -382,7 +391,7 @@ v8::Handle<v8::Value> Quit(const v8::Arguments& args) {
// If not arguments are given args[0] will yield undefined which
// converts to the integer value 0.
int exit_code = args[0]->Int32Value();
- exit(exit_code);
+ ExitShell(exit_code);
return v8::Undefined();
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698