据我了解 Emscripten 工作模型,它不支持共享状态。但是,我可以在 SDL 音频回调和主循环之间共享全局变量,如果我理解正确的话,这是不可能的。 emscripten 是否在主线程上执行音频回调,因此这是可能的,还是我完全误解了工作概念和全局变量共享?
(我的假设是音频回调在工作线程中执行)。
注意:我指的是在没有 pthreads 支持的情况下编译的 emscripten。
最佳答案
Does emscripten execute the audio callback on the main thread
是的。
据我所知,浏览器中的 Javascript(无论是否由 C++ 编译)无法从主线程播放音频。
如https://github.com/kripken/emscripten/blob/1.36.4/src/library_sdl.js所示, Emscripten 在底层使用 AudioContext,并查看 https://developer.mozilla.org/en/docs/Web/API/AudioContext和 https://developer.mozilla.org/en-US/docs/Web/API/DedicatedWorkerGlobalScope ,AudioContext只能在主线程中创建,不能在Worker范围内访问。
在https://developer.mozilla.org/en/docs/Web/API/AudioContext这是对 AudioWorker 的提及,但它说明了 createAudioWorker...
Creates an AudioWorkerNode, which can interact with a web worker thread to generate, process, or analyse audio directly. This was added to the spec on August 29 2014, and is not implemented in any browser yet.
关于c++ - 带有 SDL 音频的 Emscripten 工作模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37317949/