Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

boyanio/wasm-workers

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wasm Workers

Demo project showing how to use WebAssembly and Web Workers.

Build

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:

  1. Copy the contents of mutex.wast into the generated worker.wast file just above the line (export "_colorCells" (func $_colorCells))
  2. Delete the two mutex imports __ZNSt3__25mutex4lockEv and __ZNSt3__25mutex4lockEv as we have provided implementation for them.
  3. Change memory import to (import "env" "memory" (memory $memory 256 256 shared)) (add shared at 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.

Run

Configure any Web server to point to the build folder.

Compatibility

For now, only Chrome supports SharedArrayBuffer (and hence shared WebAssembly memory).

Releases

Packages

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.