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

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

Issue 11970009: Make the Isolate parameter mandatory in Locker and Unlocker classes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased. Added TODO. Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-lockers.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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 delete semaphore; 195 delete semaphore;
196 semaphore = NULL; 196 semaphore = NULL;
197 context.Dispose(); 197 context.Dispose();
198 } 198 }
199 199
200 200
201 class LoopingThread : public v8::internal::Thread { 201 class LoopingThread : public v8::internal::Thread {
202 public: 202 public:
203 LoopingThread() : Thread("LoopingThread") { } 203 LoopingThread() : Thread("LoopingThread") { }
204 void Run() { 204 void Run() {
205 v8::Locker locker; 205 v8::Locker locker(CcTest::default_isolate());
206 v8::HandleScope scope; 206 v8::HandleScope scope;
207 v8_thread_id_ = v8::V8::GetCurrentThreadId(); 207 v8_thread_id_ = v8::V8::GetCurrentThreadId();
208 v8::Handle<v8::ObjectTemplate> global = 208 v8::Handle<v8::ObjectTemplate> global =
209 CreateGlobalTemplate(Signal, DoLoop); 209 CreateGlobalTemplate(Signal, DoLoop);
210 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global); 210 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global);
211 v8::Context::Scope context_scope(context); 211 v8::Context::Scope context_scope(context);
212 CHECK(!v8::V8::IsExecutionTerminating()); 212 CHECK(!v8::V8::IsExecutionTerminating());
213 // Run a loop that will be infinite if thread termination does not work. 213 // Run a loop that will be infinite if thread termination does not work.
214 v8::Handle<v8::String> source = 214 v8::Handle<v8::String> source =
215 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); 215 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
216 v8::Script::Compile(source)->Run(); 216 v8::Script::Compile(source)->Run();
217 context.Dispose(); 217 context.Dispose();
218 } 218 }
219 219
220 int GetV8ThreadId() { return v8_thread_id_; } 220 int GetV8ThreadId() { return v8_thread_id_; }
221 221
222 private: 222 private:
223 int v8_thread_id_; 223 int v8_thread_id_;
224 }; 224 };
225 225
226 226
227 // Test that multiple threads using default isolate can be terminated 227 // Test that multiple threads using default isolate can be terminated
228 // from another thread when using Lockers and preemption. 228 // from another thread when using Lockers and preemption.
229 TEST(TerminateMultipleV8ThreadsDefaultIsolate) { 229 TEST(TerminateMultipleV8ThreadsDefaultIsolate) {
230 { 230 {
231 v8::Locker locker; 231 v8::Locker locker(CcTest::default_isolate());
232 v8::V8::Initialize(); 232 v8::V8::Initialize();
233 v8::Locker::StartPreemption(1); 233 v8::Locker::StartPreemption(1);
234 semaphore = v8::internal::OS::CreateSemaphore(0); 234 semaphore = v8::internal::OS::CreateSemaphore(0);
235 } 235 }
236 const int kThreads = 2; 236 const int kThreads = 2;
237 i::List<LoopingThread*> threads(kThreads); 237 i::List<LoopingThread*> threads(kThreads);
238 for (int i = 0; i < kThreads; i++) { 238 for (int i = 0; i < kThreads; i++) {
239 threads.Add(new LoopingThread()); 239 threads.Add(new LoopingThread());
240 } 240 }
241 for (int i = 0; i < kThreads; i++) { 241 for (int i = 0; i < kThreads; i++) {
242 threads[i]->Start(); 242 threads[i]->Start();
243 } 243 }
244 // Wait until all threads have signaled the semaphore. 244 // Wait until all threads have signaled the semaphore.
245 for (int i = 0; i < kThreads; i++) { 245 for (int i = 0; i < kThreads; i++) {
246 semaphore->Wait(); 246 semaphore->Wait();
247 } 247 }
248 { 248 {
249 v8::Locker locker; 249 v8::Locker locker(CcTest::default_isolate());
250 for (int i = 0; i < kThreads; i++) { 250 for (int i = 0; i < kThreads; i++) {
251 v8::V8::TerminateExecution(threads[i]->GetV8ThreadId()); 251 v8::V8::TerminateExecution(threads[i]->GetV8ThreadId());
252 } 252 }
253 } 253 }
254 for (int i = 0; i < kThreads; i++) { 254 for (int i = 0; i < kThreads; i++) {
255 threads[i]->Join(); 255 threads[i]->Join();
256 delete threads[i]; 256 delete threads[i];
257 } 257 }
258 { 258 {
259 v8::Locker locker; 259 v8::Locker locker(CcTest::default_isolate());
260 v8::Locker::StopPreemption(); 260 v8::Locker::StopPreemption();
261 } 261 }
262 262
263 delete semaphore; 263 delete semaphore;
264 semaphore = NULL; 264 semaphore = NULL;
265 } 265 }
266 266
267 267
268 int call_count = 0; 268 int call_count = 0;
269 269
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 CHECK(!v8::V8::IsExecutionTerminating()); 365 CHECK(!v8::V8::IsExecutionTerminating());
366 v8::Handle<v8::String> source = 366 v8::Handle<v8::String> source =
367 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); 367 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
368 v8::Script::Compile(source)->Run(); 368 v8::Script::Compile(source)->Run();
369 CHECK(!v8::V8::IsExecutionTerminating()); 369 CHECK(!v8::V8::IsExecutionTerminating());
370 // Check we can run JS again after termination. 370 // Check we can run JS again after termination.
371 CHECK(v8::Script::Compile(v8::String::New("function f() { return true; }" 371 CHECK(v8::Script::Compile(v8::String::New("function f() { return true; }"
372 "f()"))->Run()->IsTrue()); 372 "f()"))->Run()->IsTrue());
373 context.Dispose(); 373 context.Dispose();
374 } 374 }
375
OLDNEW
« no previous file with comments | « test/cctest/test-lockers.cc ('k') | test/cctest/test-threads.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698