emscripten-core / emscripten-core/emscripten

embind cannot be initialized correctly in a thread created in static constructor

Open
#19,849 6 comments 0 reactions 0 assignees View on GitHub
embind
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

I found this bug because I created a thread in `wasmfs_before_preload()`, which has `__attribute__((init_priority(100)))`.

When the thread runs, embind has not been fully initialized in main thread. So `Module['__embind_initialize_bindings']` did not register the types for me, but set `initializedJS` to true.

I did not use embind in thread created in `wasmfs_before_preload`, but the worker is reused in another thread, and in that thread embind does not work, caused a crash in my app.

I hope we can have a way to ensure `wasm_init_ctors` are completed, or embind inited, when `spawnthread` get called.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.