Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/test/browser/test_em_asm_blocking.cpp
4150 views
1
#include <assert.h>
2
#include <emscripten/em_asm.h>
3
#include <stdio.h>
4
#include <thread>
5
#include <math.h>
6
7
std::atomic<int> ret;
8
9
void foo() {
10
int len = MAIN_THREAD_EM_ASM_INT({
11
var elem = document.getElementById('elem');
12
window.almost_PI = 3.14159;
13
return elem.innerText.length;
14
});
15
double almost_PI = MAIN_THREAD_EM_ASM_DOUBLE({
16
// read a double from the main thread
17
return window.almost_PI;
18
});
19
printf("almost PI: %f\n", almost_PI);
20
assert(fabs(almost_PI - 3.14159) < 0.001);
21
ret = len;
22
}
23
24
int main() {
25
std::thread t(foo);
26
t.join();
27
printf("ret: %d\n", ret.load());
28
return ret.load();
29
}
30
31