emscripten-core / emscripten-core/emscripten

Fetch API with pthreads has missing symbols

Aperta
#7,490 18 commenti 0 reazioni 0 assegnatari Vedi su GitHub
multithreading
Lingua principale
C++
Stelle
27.6k
Fork
3.6k
Merge medio
1g 14h
PR unite (30g)
125

Descrizione

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:
```python
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?

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia da tools/shared.py, dove viene generato fetch-worker.js, e confronta le relative funzioni importate con il percorso pthread_mutex_lock.c collegato nell’issue. Esamina la discussione sul pthread worker in #7024 e traccia i simboli mancanti, incluso __pthread_ptr; il lavoro è completato quando i Fetch workers possono allocare memoria contemporaneamente senza generare ReferenceErrors.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
c, cpp, javascript, python, wasm
Ambito
compilers, tooling, web-dev
Tipo di issue
Bug
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.