title: Emscripten: Can't using emscripten::val in pthread
body: <p>I'm working on project to attach video from c++.</p>
  <p>I have success create video element from c++.</p>
  <pre><code>video = emscripten::val::global(&quot;document&quot;).call&lt;emscripten::val&gt;(&quot;createElement&quot;, emscripten::val(&quot;video&quot;));
  video.set(&quot;src&quot;, emscripten::val(&quot;http://jplayer.org/video/webm/Big_Buck_Bunny_Trailer.webm&quot;));  
  video.set(&quot;crossOrigin&quot;, emscripten::val(&quot;Anonymous&quot;));
  video.set(&quot;autoplay&quot;, emscripten::val(true));
  video.call&lt;void&gt;(&quot;load&quot;);
  </code></pre>
  <p>But the problem came up is I have to wait until video buffer load enough to play.</p>
  <p>My solution is using pthread to create thread wait until video buffer load enough and do stuff with the video.</p>
  <pre><code> pthread_create(&amp;threadVideo, NULL, attachVideo, NULL);
  </code></pre>
  <p>And inside attachVideo function</p>
  <pre><code>void *attachVideo(void *arg)
  {
      pthread_detach(pthread_self());
      cout &lt;&lt; &quot;ready to run&quot; &lt;&lt; endl;
      cout &lt;&lt; &quot;readyState: &quot; &lt;&lt; video[&quot;readyState&quot;].as&lt;int&gt;() &lt;&lt; endl;
      pthread_exit(NULL);
  }
  </code></pre>
  <p>And when I run it cameout error: <strong>Cannot read properties of undefined (reading 'value')&quot;</strong></p>
  <p>Can someone help me with this ?</p>