emscripten-core / emscripten-core/emscripten
Malloc and free operations seem to be deadlocked
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
We have an application where we are running wasm code in a chrome extension.
The wasm main loop runs in the main browser thread and there are some web workers ( approximately 8-9 in number) running other wasm threads. The problem is that the main loop as well as the workers seem to get deadlocked when trying to allocate / deallocate memory via the malloc/free calls .
There are calls to _free from one or more threads which waits on a lock and never returns and similarly there are one or more calls to _malloc from the workers which also never return. Thus, both the operations seem to be deadlocked.
Here are two such stacktraces:
```
Stack trace in browser main thread:
_emscripten_main_thread_process_queued_calls (extension.wasm:0x7bf427)
Module._emscripten_main_thread_process_queued_calls (extension.js:10386)
_emscripten_futex_wait (extension.js:7640)
___timedwait_cp (extension.wasm:0x7c0dc5)
___timedwait (extension.wasm:0x7c0c72)
___pthread_mutex_timedlock (extension.wasm:0x7c0c0f)
___pthread_mutex_lock (extension.wasm:0x7c0b0c)
_free (extension.wasm:0x7bd553)
...
```
```
Stack trace in worker thread:
_emscripten_futex_wait (extension.js:7616)
___timedwait_cp (extension.wasm:0x7c0dec)
___timedwait (extension.wasm:0x7c0c72)
___pthread_mutex_timedlock (extension.wasm:0x7c0c0f)
___pthread_mutex_lock (extension.wasm:0x7c0b0c)
_malloc (extension.wasm:0x7bb519)
...
```
The values of the `addr and val` parameters to the function `_emscripten_futex_wait `is the same for all the stuck threads and are as follows:
```
addr: 1328724
val: -2147483632
```
Contributor guide
Assessment
This issue has not been assessed yet.