-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Webassembly worker thread will hang if printf is used in threads. #8325
Comments
Yeah unfortunately this is a problem/limitation I'm all too familiar with. Solutions:
to something like this:
This is the solution I'm using myself. TLDR: Don't use thread.join() on the main thread. |
@VirtualTim is right. I would add that problem is nothing to do with printf. The problem is that the thread itself is not even starting. You can't start a new thread without yielding the event loop since starting a new threads involves, among other things, postMessage() between the main thread and the new worker. You might also find This issue is common enough and confusing enough that perhaps its worth detecting it and erroring in |
Just tried with @VirtualTim's third idea. The Here is the new html
|
I think the issue must be some other interaction then. I can run the following with no problems:
Compile with: Maybe there's something going on with module workers and threads? Or maybe lto is doing something weird? |
This example works because there is no web worker involved. When we run |
Just want to clarify that, in my original example, the web worker was created in a separate JavaScript file. |
Can you explain what you mean by "the web worker was created in a separate JavaScript file." Are you saying that you created the worker yourself and loaded the emscripten generated JS into it? If so, I doubt this will work. Normally emscripten takes care of creating any workers it needs. Also I believe that and a lot of code in emscripten relies on the emscripten-generated JS running in the browser main thread, not in a worker. |
Sorry about the confusion, let me try to clarify it again :) In the original example, I first compiled the c files to expose the c function
I found that if I don't use the
" I believe that and a lot of code in emscripten relies on the emscripten-generated JS running in the browser main thread, not in a worker." |
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant. |
In my c program, if printf is used in a thread, the thread won't print anything and won't finish either.
threadprint.zip
The following is my emcc info.
emcc -v
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 1.38.27
clang version 6.0.1 (https://github.com/kripken/emscripten-fastcomp-clang.git 5f5d737f1cfd84e1fcdeca85889b9f85ce7f51fb) (https://github.com/kripken/emscripten-fastcomp.git 9a451c3a09af0fb887413bba5e3e7c340d695ad2) (emscripten 1.38.27 : 1.38.27)
Target: x86_64-pc-windows-msvc
Thread model: posix
The text was updated successfully, but these errors were encountered: