Multithreaded JavaScript

Concurrency Beyond the Event Loop

I'm co-writing a book with Bryan English titled Multithreaded JavaScript. It's currently undergoing a lot of content writing but it should be ready for purchase by the end of 2021.

Multithreaded JavaScript Book Cover
Multithreaded JavaScript Book Cover

Traditionally, JavaScript has been a single-threaded language. Nearly all online forum posts, books, online documentation, and libraries refer to the language as single threaded. Thanks to recent advancements in the language—such as the Atomics and SharedArrayBuffers objects and web workers in the browser—JavaScript is now a multi-threaded language. These features will go down as being the biggest paradigm shift for the world's most popular programming language.

Multithreaded JavaScript explores the various features that JavaScript runtimes have at their disposal for implementing multithreaded programming, providing both practical real-world examples, as well as reference material.

  • Learn what multithreaded programming is and how you can benefit from it
  • Understand the differences between a web worker, a service worker, and a worker thread
  • Know when and when not to use threads in an application
  • Orchestrate communication between threads by leveraging the Atomics object
  • Build high-performance applications using the knowledge you gain from this book
  • Benchmark performance to learn if you'll benefit from multithreading

Tentative Table of Contents

  • Intro
    • What are Threads?
    • Concurrency vs Parallelism
    • Single Threaded Nature of JavaScript
    • Hidden Threads
    • Threads in C
  • Browser
    • Dedicated Workers
    • Shared Workers
    • Service Workers
    • Patterns and Libraries
  • Node.js
    • Alternatives
    • worker_threads node core module
    • Happycoin, revisited
    • 3rd party modules
  • Shared Memory
    • Intro Shared Memory
    • SharedArrayBuffer and TypedArrays
    • Atomic Methods for Data Manipulation
    • Atomicity Concerns
    • Serialization Patterns
  • Advanced Shared Memory
    • Atomic Methods for Coordination
    • Timing and Non-Determinism
    • Example Application
    • Atomics and Events
  • Multithreaded Patterns
    • Thread Pool
    • Locks
    • Streaming Data
    • Database
    • Actor Pattern
  • Web Assembly
    • Introduction
    • Emscripten / Compilation
    • AssemblyScript
  • Benchmarks
    • When not to use
    • When to use
    • Caveats
    • Serialization Cost
Thomas Hunter II Avatar

Thomas has contributed to dozens of enterprise Node.js services and has worked for a company dedicated to securing Node.js. He has spoken at several conferences on Node.js and JavaScript, is an O'Reilly published author, and is an organizer of NodeSchool SF.