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

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

Issue 23538007: Drop GetCurrentThreadId() and TerminateExecution(int) from the external API. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 3 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 | « src/api.cc ('k') | no next file » | 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 v8::Handle<v8::String> source = 185 v8::Handle<v8::String> source =
186 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); 186 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
187 v8::Script::Compile(source)->Run(); 187 v8::Script::Compile(source)->Run();
188 188
189 thread.Join(); 189 thread.Join();
190 delete semaphore; 190 delete semaphore;
191 semaphore = NULL; 191 semaphore = NULL;
192 } 192 }
193 193
194 194
195 class LoopingThread : public v8::internal::Thread {
196 public:
197 LoopingThread() : Thread("LoopingThread") { }
198 void Run() {
199 v8::Locker locker(CcTest::default_isolate());
200 v8::HandleScope scope(CcTest::default_isolate());
201 v8_thread_id_ = v8::V8::GetCurrentThreadId();
202 v8::Handle<v8::ObjectTemplate> global =
203 CreateGlobalTemplate(Signal, DoLoop);
204 v8::Handle<v8::Context> context =
205 v8::Context::New(v8::Isolate::GetCurrent(), NULL, global);
206 v8::Context::Scope context_scope(context);
207 CHECK(!v8::V8::IsExecutionTerminating());
208 // Run a loop that will be infinite if thread termination does not work.
209 v8::Handle<v8::String> source =
210 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
211 v8::Script::Compile(source)->Run();
212 }
213
214 int GetV8ThreadId() { return v8_thread_id_; }
215
216 private:
217 int v8_thread_id_;
218 };
219
220
221 // Test that multiple threads using default isolate can be terminated
222 // from another thread when using Lockers and preemption.
223 TEST(TerminateMultipleV8ThreadsDefaultIsolate) {
224 {
225 v8::Locker locker(CcTest::default_isolate());
226 v8::V8::Initialize();
227 v8::Locker::StartPreemption(1);
228 semaphore = new v8::internal::Semaphore(0);
229 }
230 const int kThreads = 2;
231 i::List<LoopingThread*> threads(kThreads);
232 for (int i = 0; i < kThreads; i++) {
233 threads.Add(new LoopingThread());
234 }
235 for (int i = 0; i < kThreads; i++) {
236 threads[i]->Start();
237 }
238 // Wait until all threads have signaled the semaphore.
239 for (int i = 0; i < kThreads; i++) {
240 semaphore->Wait();
241 }
242 {
243 v8::Locker locker(CcTest::default_isolate());
244 for (int i = 0; i < kThreads; i++) {
245 v8::V8::TerminateExecution(threads[i]->GetV8ThreadId());
246 }
247 }
248 for (int i = 0; i < kThreads; i++) {
249 threads[i]->Join();
250 delete threads[i];
251 }
252 {
253 v8::Locker locker(CcTest::default_isolate());
254 v8::Locker::StopPreemption();
255 }
256
257 delete semaphore;
258 semaphore = NULL;
259 }
260
261
262 int call_count = 0; 195 int call_count = 0;
263 196
264 197
265 void TerminateOrReturnObject(const v8::FunctionCallbackInfo<v8::Value>& args) { 198 void TerminateOrReturnObject(const v8::FunctionCallbackInfo<v8::Value>& args) {
266 if (++call_count == 10) { 199 if (++call_count == 10) {
267 CHECK(!v8::V8::IsExecutionTerminating()); 200 CHECK(!v8::V8::IsExecutionTerminating());
268 v8::V8::TerminateExecution(); 201 v8::V8::TerminateExecution();
269 return; 202 return;
270 } 203 }
271 v8::Local<v8::Object> result = v8::Object::New(); 204 v8::Local<v8::Object> result = v8::Object::New();
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 v8::Handle<v8::Context> context = 330 v8::Handle<v8::Context> context =
398 v8::Context::New(v8::Isolate::GetCurrent(), NULL, global); 331 v8::Context::New(v8::Isolate::GetCurrent(), NULL, global);
399 v8::Context::Scope context_scope(context); 332 v8::Context::Scope context_scope(context);
400 CHECK(!v8::V8::IsExecutionTerminating()); 333 CHECK(!v8::V8::IsExecutionTerminating());
401 v8::Handle<v8::String> source = 334 v8::Handle<v8::String> source =
402 v8::String::New("try { doloop(); } catch(e) { fail(); } 'completed';"); 335 v8::String::New("try { doloop(); } catch(e) { fail(); } 'completed';");
403 // Check that execution completed with correct return value. 336 // Check that execution completed with correct return value.
404 CHECK(v8::Script::Compile(source)->Run()->Equals(v8_str("completed"))); 337 CHECK(v8::Script::Compile(source)->Run()->Equals(v8_str("completed")));
405 } 338 }
406 339
OLDNEW
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698