File: test_em_asm_blocking.cpp

package info (click to toggle)
emscripten 3.1.69%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 121,872 kB
  • sloc: ansic: 636,110; cpp: 425,974; javascript: 78,401; python: 58,404; sh: 49,154; pascal: 5,237; makefile: 3,365; asm: 2,415; lisp: 1,869
file content (29 lines) | stat: -rw-r--r-- 632 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <assert.h>
#include <emscripten/em_asm.h>
#include <stdio.h>
#include <thread>
#include <math.h>

std::atomic<int> ret;

void foo() {
  int len = MAIN_THREAD_EM_ASM_INT({
    var elem = document.getElementById('elem');
    window.almost_PI = 3.14159;
    return elem.innerText.length;
  });
  double almost_PI = MAIN_THREAD_EM_ASM_DOUBLE({
    // read a double from the main thread
    return window.almost_PI;
  });
  printf("almost PI: %f\n", almost_PI);
  assert(fabs(almost_PI - 3.14159) < 0.001);
  ret = len;
}

int main() {
  std::thread t(foo);
  t.join();
  printf("ret: %d\n", ret.load());
  return ret.load();
}