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
custom worker runs multiple times when compiled with pthreads #19210
Comments
The 4 requests would seem to correspond to the 4 worker threads that correspond to The new threads should load |
I don't think so. In the screenshot I posted above, you can see the multiple fetches to In either case, the console.log can only appear from my worker so I'm pretty certain its being called from the other workers from some reason |
Can you using devtools to figure out why |
I think I've figured it out - this is part of // file: a.out.js
worker.postMessage({
cmd: 'load',
urlOrBlob: Module['mainScriptUrlOrBlob'] || _scriptDir,
wasmMemory: wasmMemory,
wasmModule: wasmModule,
}) and // file: a.out.js
if (ENVIRONMENT_IS_WORKER) {
_scriptDir = self.location.href
} Indeed, if I rewrite my worker as follows, everything works as expected(if indeed it is expected to have console.log('called')
var Module = {
mainScriptUrlOrBlob: 'a.out.js',
}
importScripts('a.out.js') |
I see, so when you load Sounds like you found the solution using the |
Looks like its documented here, although I don't see how I could've found it without knowing exactly what I was looking for 🤷 Either way, I guess nothing survives in this issue? |
Yes, I think this can be closed. |
Well, hopefully this prevents someone from scratching their heads in confusion in the future. Thanks for your help! Closing this. |
This is unrelated but it arises out of this - is there a way to bundle |
We don't currently have a way to do that no. Presumably it would result in the same number of bytes over the network though? |
Yes, it will probably be cached by the browser but I think bundling might be more performant overall. |
Here's the output of
emcc -v
I have defined a worker which does nothing but call the emscripten glue code(
a.out.js
).The C++ code is irrelevant I think. I used to following to reproduce the issue
The JS does just one thing - it creates a worker from
worker.js
I compile the code with the following command
emcc main.cpp --bind -s PTHREAD_POOL_SIZE=4 -pthread -O2 -s ALLOW_MEMORY_GROWTH=1
Notice that the worker is executed multiple times(confirmed by the multiple console.logs). You can also see in the dev tools that its requested more than once by
a.out.worker.js
which I find confusing.Is this expected behavior? Why is
a.out.worker.js
executingmy_worker.js
? In this example, this perhaps isn't that big of an issue. However, the real code I had definedonmessage
on the worker as followsThe problem was, since this code was being run by
a.out.worker.js
as well, it redefined theironmessage
and my worker was getting a bunch of events I didn't expect it to.Is there some flag or some configuration I'm missing here? Thanks!
The text was updated successfully, but these errors were encountered: