Alexandr Gribkov
unread,Jul 26, 2022, 4:15:31 AM7/26/22Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to emscripten-discuss
```
Emscripten: 3.1.13
EMBIND
CMAKE linking/compiling
set(CMAKE_CXX_FLAGS "-O0 -lembind -pthread -g3 -s ALLOW_MEMORY_GROWTH=1 -s USE_PTHREADS=1")
${PROJECT_NAME}
"-s WASM=1"
"-s EXPORT_ES6=1"
"-s ALLOW_MEMORY_GROWTH=1"
"-s ENVIRONMENT=web,worker"
"-s PTHREAD_POOL_SIZE='navigator.hardwareConcurrency'"
"-s MODULARIZE=1"
```
On C++ side guys are using code with pthreads
Emscripten produces the following files
```
wasm_test.js
wasm_test.wasm
wasm_test.worker.js
```
on the frontend side, we are using the following code to launch the binary within web worker produced by emscripten
```
const worker = new Worker('%PUBLIC_URL%/test/test_web.worker.js');
const memory = getSharedMemory()
worker.onmessage = (data) => {
if (data.data.cmd === 'loaded') {
worker.postMessage({ cmd: 'run', threadInfoStruct: ??? })
}
};
worker.onerror = console.log.bind(null, 'on error ');
fetch('/test/test_web.wasm').then(data => data.arrayBuffer()).then(bytes => {
const mod = WebAssembly.compile(bytes);
mod.then((wasmModule) => {
worker.postMessage({
cmd: 'load',
wasmModule,
urlOrBlob: '%PUBLIC_URL%/test/test_web.js',
wasmMemory: memory
})
})
});
```
Worker firing the `loaded` event but I can't figure out how to launch the run event/method
What is the right payload for the following event `worker.postMessage({ cmd: 'run', ??? })`???
How to run any C++ bound method?