title: nodejs native addon multithreading
body: <p>I have developed native modules for nodejs during a little period of time and some cases aren't quite clear for me. Unfortunately v8 documentation isn't very good.</p>
  
  <p>So there are one of the interesting field for me. 
  First of all is it possible to use <code>std::thread</code> in main native module thread? Documentation say that I can use libuv functions and run async operations, but inside this library we haven't access to v8 objects. But what if I want to parallel my computations synchronous in main thread and, for example, modify some JS object properties with its result in another thread?</p>
  
  <p>I tried following code:</p>
  
  <pre><code>double result;
  void myFunction(Local&lt;Value&gt; a, Local&lt;Value&gt; b)
  {
      std::cout &lt;&lt; "from thread " &lt;&lt; std::this_thread::get_id() &lt;&lt; " " &lt;&lt; std::endl;
      result = a-&gt;NumberValue() + b-&gt;NumberValue();
  }
  void add(const FunctionCallbackInfo&lt;Value&gt;&amp; args)
  {
    Isolate* isolate = args.GetIsolate();
    std::cout &lt;&lt; "main "&lt;&lt; std::this_thread::get_id() &lt;&lt; std::endl;
    thread thread(myFunction, args[0], args[1]);
    thread.join();
    args.GetReturnValue().Set(Number::New(isolate, result));
  }
  </code></pre>
  
  <p>And it works as I expect, but why if we haven't access to v8 objects in another thread ?</p>
  
  <p>I also tried change result to v8::Number type and create it inside myFunction via current isolate and new isolate, but get seg fault.</p>