Description
I've been attempting to port some of our projects to support Emscripten (v1.38.16), and I've started to encounter Uncaught ReferenceError
s when both the worker thread and another thread are allocating at the same time. If a thread is already allocating when the Fetch worker attempts to allocate, it will fail the second conditional here: https://github.com/kripken/emscripten/blob/4bba062e95fb319ae9ba89797c88a0eef3dea1be/system/lib/libc/musl/src/thread/pthread_mutex_lock.c#L7-L9
The Fetch worker will then attempt to call __pthread_mutex_timedlock()
which will then result in this error Uncaught ReferenceError: ___pthread_mutex_timedlock is not defined
. I found the tools/shared.py
script which generates the fetch-worker.js
file and began adding all of the missing functions (as the reference errors came up) and ended up with:
funcs_to_import = ['alignUp', 'getTotalMemory', 'stringToUTF8', 'intArrayFromString', 'lengthBytesUTF8', 'stringToUTF8Array', '_emscripten_is_main_runtime_thread', '_emscripten_futex_wait', '_emscripten_futex_wake', '_pthread_self']
asm_funcs_to_import = ['_malloc', '_free', '_sbrk', '___pthread_mutex_lock', '___pthread_mutex_unlock', '___pthread_mutex_timedlock', '___pthread_mutex_trylock', '___timedwait', '___pthread_setcancelstate']
Unfortunately, _pthread_self()
requires __pthread_ptr
which I believe requires the usage of pthread_create()
? It seems like the solution is to make the worker thread more like a pthread as suggested in #7024?