OLD | NEW |
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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 context.Dispose(); | 214 context.Dispose(); |
215 } | 215 } |
216 | 216 |
217 int GetV8ThreadId() { return v8_thread_id_; } | 217 int GetV8ThreadId() { return v8_thread_id_; } |
218 | 218 |
219 private: | 219 private: |
220 int v8_thread_id_; | 220 int v8_thread_id_; |
221 }; | 221 }; |
222 | 222 |
223 | 223 |
224 // Test that multiple threads using V8 can be terminated from another | 224 // Test that multiple threads using default isolate can be terminated |
225 // thread when using Lockers and preemption. | 225 // from another thread when using Lockers and preemption. |
226 TEST(TerminateMultipleV8Threads) { | 226 TEST(TerminateMultipleV8ThreadsDefaultIsolate) { |
227 { | 227 { |
228 v8::Locker locker; | 228 v8::Locker locker; |
229 v8::V8::Initialize(); | 229 v8::V8::Initialize(); |
230 v8::Locker::StartPreemption(1); | 230 v8::Locker::StartPreemption(1); |
231 semaphore = v8::internal::OS::CreateSemaphore(0); | 231 semaphore = v8::internal::OS::CreateSemaphore(0); |
232 } | 232 } |
233 LoopingThread thread1(i::Isolate::Current()); | 233 const int kThreads = 10; |
234 thread1.Start(); | 234 i::List<LoopingThread*> threads(kThreads); |
235 LoopingThread thread2(i::Isolate::Current()); | 235 for (int i = 0; i < kThreads; i++) { |
236 thread2.Start(); | 236 threads.Add(new LoopingThread(i::Isolate::Current())); |
237 // Wait until both threads have signaled the semaphore. | 237 } |
238 semaphore->Wait(); | 238 for (int i = 0; i < kThreads; i++) { |
239 semaphore->Wait(); | 239 threads[i]->Start(); |
| 240 } |
| 241 // Wait until all threads have signaled the semaphore. |
| 242 for (int i = 0; i < kThreads; i++) { |
| 243 semaphore->Wait(); |
| 244 } |
240 { | 245 { |
241 v8::Locker locker; | 246 v8::Locker locker; |
242 v8::V8::TerminateExecution(thread1.GetV8ThreadId()); | 247 for (int i = 0; i < kThreads; i++) { |
243 v8::V8::TerminateExecution(thread2.GetV8ThreadId()); | 248 v8::V8::TerminateExecution(threads[i]->GetV8ThreadId()); |
| 249 } |
244 } | 250 } |
245 thread1.Join(); | 251 for (int i = 0; i < kThreads; i++) { |
246 thread2.Join(); | 252 threads[i]->Join(); |
| 253 delete threads[i]; |
| 254 } |
247 | 255 |
248 delete semaphore; | 256 delete semaphore; |
249 semaphore = NULL; | 257 semaphore = NULL; |
250 } | 258 } |
251 | 259 |
252 | 260 |
253 int call_count = 0; | 261 int call_count = 0; |
254 | 262 |
255 | 263 |
256 v8::Handle<v8::Value> TerminateOrReturnObject(const v8::Arguments& args) { | 264 v8::Handle<v8::Value> TerminateOrReturnObject(const v8::Arguments& args) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 v8::Handle<v8::String> source = | 359 v8::Handle<v8::String> source = |
352 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); | 360 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); |
353 v8::Script::Compile(source)->Run(); | 361 v8::Script::Compile(source)->Run(); |
354 CHECK(!v8::V8::IsExecutionTerminating()); | 362 CHECK(!v8::V8::IsExecutionTerminating()); |
355 // Check we can run JS again after termination. | 363 // Check we can run JS again after termination. |
356 CHECK(v8::Script::Compile(v8::String::New("function f() { return true; }" | 364 CHECK(v8::Script::Compile(v8::String::New("function f() { return true; }" |
357 "f()"))->Run()->IsTrue()); | 365 "f()"))->Run()->IsTrue()); |
358 context.Dispose(); | 366 context.Dispose(); |
359 } | 367 } |
360 | 368 |
OLD | NEW |