A journey of multithreading using WebAssembly
summary
Shows how WebAssembly gains real threads by using a shared linear memory (memory with the shared: true flag), SharedArrayBuffer and Atomics.wait/notify, with compilation via Emscripten and the wasm binary toolkit (wabt). Builds a C++ matrix painter (3x3) that initially reports 10 painted cells for 9 cells due to races, fixes it by providing mutexes implemented with atomic wait/notify. Demonstrates emscripten switches like -s USE_PTHREADS, measures runtime (single ~4s, two threads ~6s better, many threads up to ~13s worse) and notes Chrome enables SAB by default while other browsers need flags.
AI-written summary · about
chapters (12)
- 0:00Introduction to multithreading
- 1:15Defining threads of execution
- 2:20Multitasking vs multithreading
- 3:24When and why to use threads
- 4:56WebAssembly and threading
- 6:40Understanding web workers
- 8:18WebAssembly thread proposal
- 10:02Implementing shared memory
- 11:57Security and browser support
- 13:27Synchronization and atomics
- 15:12Practical coding demonstration
- 23:55Conclusion and future outlook
related talks
22mUsing WebAssembly and Threads
52mWebAssembly: Taking Your C++ and Going Places
39mBringing the power of C++ to the web
28mWebAssembly: Of Portability, and Performance
25mExploit Parallelism for AI Workloads with WASM and OpenMP
26mWebAssembly as cross-platform architecture?!
27mWebAssembly for Performant Interactivity
46mA State Of WebAssembly - The Browser is now a real VM
