Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dlopen + pthreads with FS not working #21576

Open
ravisumit33 opened this issue Mar 20, 2024 · 3 comments
Open

dlopen + pthreads with FS not working #21576

ravisumit33 opened this issue Mar 20, 2024 · 3 comments

Comments

@ravisumit33
Copy link
Contributor

ravisumit33 commented Mar 20, 2024

Please include the following in your bug report:

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.35 (a90c5abb489c516f59c0d16864d953d4bedd37da)
clang version 17.0.0 (https://github.com/llvm/llvm-project 6865cff8ea8b07d9f2385fd92cecb422404f0f35)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: ~/emsdk/upstream/bin

We currently do runtime dynamic linking (dlopen) in our app which is single-threaded. For dlopen to work, we have used FS.createLazyFile for all the side modules in Module.preInit. When dlopen is called side-modules are downloaded and used. Now, we are trying to enable pthreads in our app. When dlopen is called on a thread other than main application thread (on which we have mounted the side modules), FS is unable to find these mounted side modules and hence our whole logic fails. Does FS even work with pthreads? Or is there any alternate way of using dlopen with pthreads?

@ravisumit33 ravisumit33 changed the title dlopen dlopen + pthreads with FS not working Mar 20, 2024
@ravisumit33
Copy link
Contributor Author

@sbc100 Thoughts on this?

@ravisumit33
Copy link
Contributor Author

@kripken @sbc100 Please confirm if FS does supoort multithreading. If not, what are other options to try for the scenario described above?

@sbc100
Copy link
Collaborator

sbc100 commented Apr 1, 2024

The FS object only exists (or rather is only usable) on the main thread.

However, all filesystem operations in C/C++ are proxied back to the main thread. In particular with dlopen the operation is always proxied back to the main thread. So we have several test for dlopen on multiple threads so we know it works in the general case and there should no no FS operations that occur on the side module.

Can you try with the latest version of emscripten (3.1.35 is a year old now)? It could be that some of the fixes needed for side modules and threading happened in more recent versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants