Hi,
I have a question about using -s PROXY_TO_THREAD=1.
My C code has 2 entry points:
int32_T main(int32_T argc,charPtr_T *argv){
//some initialisation
#ifdef __EMSCRIPTEN__
emscripten_exit_with_live_runtime();
return 0;
}
EMSCRIPTEN_KEEPALIVE
Error_T wasmEvent(int32_T evtType, int32_T nInt, float_T nFloat, void* param) {
//handling of all events coming in from JS
return 0;
}Options used:
-s ALLOW_MEMORY_GROWTH=1 ^
-s ENVIRONMENT=web,worker ^
--shell-file ./index_template.html ^
-s SUPPORT_ERRNO=0 ^
-s MODULARIZE=1 ^
-sWASM_WORKERS ^
-pthread ^
-s PTHREAD_POOL_SIZE=1 ^
-s PROXY_TO_PTHREAD=1 ^
-s "EXPORT_NAME='wasmMod'" ^
-s EXPORTED_FUNCTIONS="['_malloc','_free','_main']" ^
-s EXPORTED_RUNTIME_METHODS="['cwrap','UTF16ToString','UTF8ToString','stringToUTF8','allocateUTF8']" ^
-o index.html
When main is called
emscripten_is_main_runtime_thread() and
emscripten_is_main_browser_thread() both return 0 as expected.
However, if I call wasmEvent from JS (using cwrap), they both return 1, so the code is not running in the same thread as main but rather in the main browser thread?
I can remember the first thread like this
mainThread = pthread_self();
and then use
emscripten_dispatch_to_thread(mainThread, EM_FUNC_SIG_VI, _wasmEvent, 0,(void*)&e, 0);
That does work, but I am unsure about the described behavior. I expected all code to run in the thread that ran main, except for specified pthreads created later.
What am I doing wrong?
Dieter