
#JavaScript
#Multithreaded
#Node_js
#C_application
#C++
#Java
The nature of JavaScript is to be single threaded. This is reflected not only in libraries and applications, but also in online forum posts, books, and online documentation. Thanks to recent advancements in the platform—such as with web workers in the browser, worker_threads in Node.js, and the Atomics and SharedArrayBuffer objects—JavaScript engineers are able to build multi-threaded applications. 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, using a spectrum of API reference material and high level programming patterns.
The ideal reader of this book is an engineer who has been writing JavaScript for a few years, and who doesn’t necessarily have experience with writing multithreaded applications or even experience with more traditionally multithreaded languages like C++ or Java. We do include some example C application code, as a sort of multithreaded lingua franca, but it’s not something that the reader is expected to be familiar with or even understand.
If you do have experience with such languages, that’s great, and this book will help you understand the JavaScript equivalent to the functionality provided by whatever language you may be familiar with. On the other hand, if you’ve only written code using JavaScript, then this book is also for you. We include information across multiple layers of learning; this includes both low-level API references, high-level patterns, and plenty of technical tangents in between to help fill in any gaps.
Goals
Perhaps the most exuberant goal of this book is to bring knowledge to the community that it’s possible to build multithreaded applications using JavaScript. Traditionally, JavaScript code was constrained to a single core, and indeed there are many Twitter threads and forum posts describing the language as such. With a title like Multithreaded JavaScript, we hope to completely dispel the notion that JavaScript applications are confined to a single core.
At a more concrete level, the goal is to teach you, the reader, several aspects about writing multithreaded JavaScript applications. By the time you’re done reading this book you’ll understand the various web worker APIs provided in browsers, their strengths and weaknesses, and when to use which. As far as Node.js goes, you’ll understand the worker threads module and how its APIs compare to those in the browser.
The book focuses on two approaches to building multithreaded applications: one using message passing and the other using shared memory. By reading this book you’ll understand the APIs used to implement each, when you might want to use one approach or the other, and in which situations they can be combined—and you’ll even get your hands dirty with some high-level patterns built upon these approaches.
Thomas Hunter II 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 JSNSD/JSNAD certified, and is an organizer of NodeSchool SF. Thomas has published four books including Distributed Systems with Node.js by O'Reilly.
Bryan is an open source JavaScript and Rust programmer and enthusiast and has worked on large enterprise systems, instrumentation, and application security. Currently he’s a Senior Open Source Software engineer at Datadog. He’s used Node.js both professionally and in personal projects since not long after its inception. He is also a Node.js core collaborator and has contributed to Node.js in many ways through several of its various Working Groups.









