Home Page Icon
Home Page
Table of Contents for
Multithreaded JavaScript
Close
Multithreaded JavaScript
by
Multithreaded JavaScript
Preface
Conventions Used in This Book
Using Code Examples
O’Reilly Online Learning
How to Contact Us
Acknowledgments
1. Introduction
What Are Threads?
Concurrency vs. Parallelism
Single-Threaded JavaScript
Hidden Threads
Threads in C: Get Rich with Happycoin
With Only the Main Thread
With Four Worker Threads
2. Browsers
Dedicated Workers
Dedicated Worker Hello World
Advanced Dedicated Worker Usage
Shared Workers
Shared Worker Hello World
Advanced Shared Worker Usage
Service Workers
Service Worker Hello World
Advanced Service Worker Concepts
Message Passing Abstractions
The RPC Pattern
The Command Dispatcher Pattern
Putting it All Together
3. Node.js
Before We Had Threads
The worker_threads Module
workerData
MessagePort
Happycoin: Revisited
With Only the Main Thread
With Four Worker Threads
Worker Pools with Piscina
A Pool Full of Happycoins
4. Shared Memory
Intro to Shared Memory
Shared Memory in the Browser
Shared Memory in Node.js
SharedArrayBuffer and TypedArrays
Atomic Methods for Data Manipulation
Atomics.add()
Atomics.and()
Atomics.compareExchange()
Atomics.exchange()
Atomics.isLockFree()
Atomics.load()
Atomics.or()
Atomics.store()
Atomics.sub()
Atomics.xor()
Atomicity Concerns
Return Values Ignore Conversion
Data Serialization
Booleans
Strings
Objects
5. Advanced Shared Memory
Atomic Methods for Coordination
Atomics.wait()
Atomics.notify()
Atomics.waitAsync()
Timing and Non-Determinism
Example of Non-Determinism
Detecting Thread Preparedness
Example Application: Conway’s Game of Life
Single-Threaded Game of Life
Multithreaded Game of Life
Atomics and Events
6. Multithreaded Patterns
Thread Pool
Pool Size
Dispatch Strategies
Example Implementation
Mutex: A Basic Lock
Streaming Data with Ring Buffers
Actor Model
Pattern Nuances
Relating to JavaScript
Example Implementation
7. WebAssembly
Your First WebAssembly
Atomic Operations in WebAssembly
Compiling C Programs to WebAssembly with Emscripten
Other WebAssembly Compilers
AssemblyScript
Happycoin in AssemblyScript
8. Analysis
When Not to Use
Low Memory Constraints
Low Core Count
Containers vs Threads
When to Use
Example Benchmark: Template Rendering
Summary of Caveats
A. Structured Clone Algorithm
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Next
Next Chapter
Multithreaded JavaScript
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset