Answered on https://github.com/emscripten-core/emscripten/issues/17523#issuecomment-1195755927
TLDR: You should let emscripten handle the creation of new workers/pthreads. No need to do any of that yourself, just call `pthread_create`. On Tue, Jul 26, 2022 at 1:15 AM Alexandr Gribkov < [email protected]> wrote: > ``` > 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? > > -- > You received this message because you are subscribed to the Google Groups > "emscripten-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/emscripten-discuss/796df541-42c8-40a3-b53e-d62c79146593n%40googlegroups.com > <https://groups.google.com/d/msgid/emscripten-discuss/796df541-42c8-40a3-b53e-d62c79146593n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "emscripten-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAL_va2-r0wVkbdgXburFv2pB-zsvBV2RmADQjxWEaatoM57Stg%40mail.gmail.com.
