Demo project showing how to use WebAssembly and Web Workers.
You need emscripten to compile the WebAssembly sources using compile-cpp.bat (or just see the exact command for non-Windows).
Next, you will need following fixes to build using shared memory and mutex:
- Copy the contents of
mutex.wastinto the generatedworker.wastfile just above the line(export "_colorCells" (func $_colorCells)) - Delete the two mutex imports
__ZNSt3__25mutex4lockEvand__ZNSt3__25mutex4lockEvas we have provided implementation for them. - Change memory import to
(import "env" "memory" (memory $memory 256 256 shared))(addsharedat the end)
You need to compile the updated worker.wast file back to .wasm. You can do this using the wat2wasm tool from WebAssembly Binary Toolkit (with --enable-threads option) or using this web demo (with the threads checkbox checked). For the former, check compile-wast.bat.
You can play around with USE_MUTEX in worker.cpp to see how locking affects multiple workers.
Configure any Web server to point to the build folder.
For now, only Chrome supports SharedArrayBuffer (and hence shared WebAssembly memory).
