changeset 14:7eb1a37c12da tip

the two parallel threads with two different isolates
author Sara
date Sat, 15 Feb 2014 13:17:49 -0800
parents 77d9e57697b1
children
files V8_tests/Two_parallel_threads_with_Two_different_Isolate/Two_threads_with_different_Isolates.cpp V8_tests/Two_parallel_threads_with_Two_different_Isolate/Two_threads_with_different_Isolates.png
diffstat 2 files changed, 63 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/V8_tests/Two_parallel_threads_with_Two_different_Isolate/Two_threads_with_different_Isolates.cpp	Sat Feb 15 13:17:49 2014 -0800
     1.3 @@ -0,0 +1,63 @@
     1.4 +#include <v8.h>
     1.5 +#include <pthread.h>
     1.6 +using namespace v8;
     1.7 +void* threadFunction(void*){
     1.8 +Isolate* isolate1 = Isolate::New();
     1.9 +  if(isolate1 == NULL){
    1.10 +   printf("Error1");
    1.11 +   return 0;
    1.12 +}
    1.13 +//Locker locker1(isolate1);
    1.14 +//isolate1->Enter();
    1.15 +Isolate::Scope isolate_scope1(isolate1);
    1.16 +HandleScope handle_scope1(isolate1);
    1.17 +Handle<Context> context1 = Context::New(isolate1);
    1.18 +  Context::Scope context_scope1(context1);
    1.19 +  Handle<String> source1 = String::NewFromUtf8(isolate1, "'Hi' + ', Sara'");
    1.20 +  Handle<Script> script1 = Script::Compile(source1);
    1.21 +  Handle<Value> result1 = script1->Run();
    1.22 +  String::Utf8Value utf81(result1);
    1.23 +  printf("%s\n", *utf81);
    1.24 +
    1.25 +//isolate1->Exit();
    1.26 +//Unlocker unlocker1(isolate1);
    1.27 +
    1.28 +  return 0;
    1.29 +
    1.30 +}
    1.31 +int main(int argc, char* argv[]) {
    1.32 +
    1.33 +  Isolate* isolate =  Isolate::New();
    1.34 +{
    1.35 +  if(isolate == NULL){
    1.36 +   printf("Error");
    1.37 +   return 0;
    1.38 +}
    1.39 +//Locker locker(isolate);
    1.40 +Isolate::Scope isolate_scope(isolate);
    1.41 +  // Create a stack-allocated handle scope.
    1.42 +  HandleScope handle_scope(isolate);
    1.43 +  // Create a new context.
    1.44 +  Handle<Context> context = Context::New(isolate);
    1.45 +  // Enter the context for compiling and running the hello world script.
    1.46 +  Context::Scope context_scope(context);
    1.47 +  // Create a string containing the JavaScript source code.
    1.48 + //isolate->Exit();
    1.49 +// Unlocker unlocker(isolate);
    1.50 + pthread_t thread_id;
    1.51 + pthread_create(&thread_id, NULL, &threadFunction,NULL);
    1.52 + pthread_join(thread_id, NULL);
    1.53 +//isolate->Enter();
    1.54 +  Handle<String> source = String::NewFromUtf8(isolate, "'Hello' + ', World!'");
    1.55 +  // Compile the source code.
    1.56 +  Handle<Script> script = Script::Compile(source);
    1.57 +  // Run the script to get the result.
    1.58 +  Handle<Value> result = script->Run();
    1.59 +  // Convert the result to an UTF8 string and print it.
    1.60 +  String::Utf8Value utf8(result);
    1.61 +  printf("%s\n", *utf8);
    1.62 +//Unlocker unlocker(isolate);
    1.63 +  return 0;
    1.64 +}
    1.65 +//isolate->Dispose();
    1.66 +}
     2.1 Binary file V8_tests/Two_parallel_threads_with_Two_different_Isolate/Two_threads_with_different_Isolates.png has changed