Skip to Content
Multithreaded Javascript
book

Multithreaded Javascript

by Thomas Hunter, Bryan English
September 2021
Intermediate to advanced
211 pages
5h 32m
English
O'Reilly Media, Inc.
Content preview from Multithreaded Javascript

Chapter 5. Advanced Shared Memory

Chapter 4 looked at using the SharedArrayBuffer object to read and write directly to a collection of shared data from across separate threads. But doing so is risky business, allowing one thread to clobber data that was written by another thread. However, thanks to the Atomics object, you are able to perform very basic operations with that data in a way that prevents data from being clobbered.

Although the basic operations provided by Atomics are convenient, you will often find yourself needing to perform more complex interactions with that data. For example, once you’ve serialized data as described in “Data Serialization”, like a 1 kilobyte string, you’ll then need to write that data to the SharedArrayBuffer instance, and none of the existing Atomics methods will allow you to set the entire value all at once.

This chapter covers additional functionality for coordinating reads and writes to shared data across threads for situations when the previously covered Atomics methods just aren’t enough.

Atomic Methods for Coordination

These methods are a little different than the ones that were already covered in “Atomic Methods for Data Manipulation”. Specificially, the methods previously covered each work with a TypedArray of any kind and may operate on both SharedArrayBuffer and ArrayBuffer instances. However, the methods listed here will only work with Int32Array and BigInt64Array instances, and they only make sense when used with SharedArrayBuffer ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Clean Code in JavaScript

Clean Code in JavaScript

James Padolsey
TypeScript Cookbook

TypeScript Cookbook

Stefan Baumgartner

Publisher Resources

ISBN: 9781098104429Errata Page