Search code examples
javascriptiosgoogle-chromewebassemblyemscripten

WASM with thread support not working on Google Chrome iOS


I have some threaded (pthread) & non-threaded WASM processes running perfectly in several versions of Google Chrome in Android, Mac OS X, Windows, etc across different machines.

I was lucky enough to get hands on an iPhone13 for testing (iOS 15.3, Chrome 97.0.4692.84). Cross Origin isolation is enabled and SharedArrayBuffer, which is needed for threaded WASM, is supported in this iOS version (https://caniuse.com/sharedarraybuffer).

Unfortunately the WASM code does not run and it stops on the first call to WASM from Javascript.

If i disable USE_PTHREADS on the emscripten compilation then the non threaded WASM works but obviously the threaded one doesn't.

My compilation is done using:

emcc -std=c++11 -O3 -s ALLOW_MEMORY_GROWTH=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=4 -s EXPORTED_RUNTIME_METHODS='["getValue"]' -s test.cpp -o test.js

Do you have any insight on why (Chrome) on iOS is failing even though there is support for things to run properly? I have some feedback of other people that claim threaded WASM running on iOS so any insight would be helpful.

I can provided barebones/example code if necessary.

Thanks


Solution

  • Just in case someone hits this issue:

    -s ALLOW_MEMORY_GROWTH=1 is the root cause of the issue. For things to work in iOS Safari/Chrome then this flag needs to be disabled -s ALLOW_MEMORY_GROWTH=0