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

Side by Side Diff: test/cctest/test-thread-termination.cc

Issue 6711068: Use v8::internal threading support in samples/shell.cc. (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 unified diff | Download patch
« no previous file with comments | « test/cctest/test-sockets.cc ('k') | test/cctest/test-threads.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 v8::Script::Compile(source)->Run(); 153 v8::Script::Compile(source)->Run();
154 CHECK(!v8::V8::IsExecutionTerminating()); 154 CHECK(!v8::V8::IsExecutionTerminating());
155 // Test that we can run the code again after thread termination. 155 // Test that we can run the code again after thread termination.
156 v8::Script::Compile(source)->Run(); 156 v8::Script::Compile(source)->Run();
157 context.Dispose(); 157 context.Dispose();
158 } 158 }
159 159
160 160
161 class TerminatorThread : public v8::internal::Thread { 161 class TerminatorThread : public v8::internal::Thread {
162 public: 162 public:
163 explicit TerminatorThread(i::Isolate* isolate) : Thread(isolate) { } 163 explicit TerminatorThread(i::Isolate* isolate)
164 : Thread(isolate, "TerminatorThread") { }
164 void Run() { 165 void Run() {
165 semaphore->Wait(); 166 semaphore->Wait();
166 CHECK(!v8::V8::IsExecutionTerminating()); 167 CHECK(!v8::V8::IsExecutionTerminating());
167 v8::V8::TerminateExecution(); 168 v8::V8::TerminateExecution();
168 } 169 }
169 }; 170 };
170 171
171 172
172 // Test that a single thread of JavaScript execution can be terminated 173 // Test that a single thread of JavaScript execution can be terminated
173 // from the side by another thread. 174 // from the side by another thread.
(...skipping 14 matching lines...) Expand all
188 189
189 thread.Join(); 190 thread.Join();
190 delete semaphore; 191 delete semaphore;
191 semaphore = NULL; 192 semaphore = NULL;
192 context.Dispose(); 193 context.Dispose();
193 } 194 }
194 195
195 196
196 class LoopingThread : public v8::internal::Thread { 197 class LoopingThread : public v8::internal::Thread {
197 public: 198 public:
198 explicit LoopingThread(i::Isolate* isolate) : Thread(isolate) { } 199 explicit LoopingThread(i::Isolate* isolate)
200 : Thread(isolate, "LoopingThread") { }
199 void Run() { 201 void Run() {
200 v8::Locker locker; 202 v8::Locker locker;
201 v8::HandleScope scope; 203 v8::HandleScope scope;
202 v8_thread_id_ = v8::V8::GetCurrentThreadId(); 204 v8_thread_id_ = v8::V8::GetCurrentThreadId();
203 v8::Handle<v8::ObjectTemplate> global = 205 v8::Handle<v8::ObjectTemplate> global =
204 CreateGlobalTemplate(Signal, DoLoop); 206 CreateGlobalTemplate(Signal, DoLoop);
205 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global); 207 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global);
206 v8::Context::Scope context_scope(context); 208 v8::Context::Scope context_scope(context);
207 CHECK(!v8::V8::IsExecutionTerminating()); 209 CHECK(!v8::V8::IsExecutionTerminating());
208 // Run a loop that will be infinite if thread termination does not work. 210 // Run a loop that will be infinite if thread termination does not work.
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 v8::Handle<v8::String> source = 351 v8::Handle<v8::String> source =
350 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); 352 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
351 v8::Script::Compile(source)->Run(); 353 v8::Script::Compile(source)->Run();
352 CHECK(!v8::V8::IsExecutionTerminating()); 354 CHECK(!v8::V8::IsExecutionTerminating());
353 // Check we can run JS again after termination. 355 // Check we can run JS again after termination.
354 CHECK(v8::Script::Compile(v8::String::New("function f() { return true; }" 356 CHECK(v8::Script::Compile(v8::String::New("function f() { return true; }"
355 "f()"))->Run()->IsTrue()); 357 "f()"))->Run()->IsTrue());
356 context.Dispose(); 358 context.Dispose();
357 } 359 }
358 360
OLDNEW
« no previous file with comments | « test/cctest/test-sockets.cc ('k') | test/cctest/test-threads.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698